1.1.0 • Published 1 year ago

@hashiprobr/react-native-aspect-image v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-native-aspect-image

A React Native Image that keeps the source aspect ratio

The AspectImage React Component is an Image that keeps the source aspect ratio if one of its dimensions is unset.

Please note that one of its dimensions must be set, either explicitly by width, height, or flexBasis, or implicitly by a positive flexGrow, an alignSelf: 'stretch' or an alignItens: 'stretch' in the parent, otherwise the image will be 0x0.

Peer dependencies

{
    "@hashiprobr/react-use-mount-and-update": "1.0.5",
    "react": "17.0.2",
    "react-native": "0.68.2"
}

Install

With npm:

npm install @hashiprobr/react-native-aspect-image

With yarn:

yarn add @hashiprobr/react-native-aspect-image

If using Expo, add the module to webpack.config.js:

const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function (env, argv) {
    const config = await createExpoWebpackConfigAsync({
        ...env,
        babel: {
            dangerouslyAddModulePathsToTranspile: [
                '@hashiprobr/react-native-aspect-image',
            ],
        },
    }, argv);
    return config;
};

If webpack.config.js does not exist, create it with:

expo customize:web

Props

namedescription
placeholderthe component shown while the source aspect ratio is being calculated (default null)

...Image props

Example

import React from 'react';

import { Text } from 'react-native';

import AspectImage from '@hashiprobr/react-native-aspect-image';

export default function MyComponent() {
    return (
        <AspectImage
            style={{ flexGrow: 1 }}
            source={require('path/to/an/asset')}
            placeholder={<Text>loading</Text>}
        />
    );
}
1.1.0

1 year ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago