1.1.0 • Published 1 year ago

@hashiprobr/react-native-rounded-view v1.1.0

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

react-native-rounded-view

A React Native View that defines its border radius by percentage

React Native offers the borderRadius style prop to define the border radius of a component. However, this prop does not accept percentage values.

The RoundedView React Component is a View that defines its border radius by percentage and has overflow: 'hidden'. It is particularly useful to create a view with circular shape.

Please note that this is not equivalent to the the border-radius CSS property, because the calculations consider the minimum between width and height. It is not possible to create a view with oval shape.

Peer dependencies

{
    "react": "17.0.2",
    "react-native": "0.68.2"
}

Install

With npm:

npm install @hashiprobr/react-native-rounded-view

With yarn:

yarn add @hashiprobr/react-native-rounded-view

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-rounded-view',
            ],
        },
    }, argv);
    return config;
};

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

expo customize:web

Props

namedescription
radiusa number representing the border radius percentage (default 50)

...View props

Example

With radius={50} (one half of the minimum between width and height).

npm.io npm.io npm.io

With radius={25} (one quarter of the minimum between width and height).

npm.io npm.io npm.io

Code for the first image. Notice how the white View has relative dimensions.

import React from 'react';

import { View, Text } from 'react-native';

import RoundedView from '@hashiprobr/react-native-rounded-view';

export default function MyComponent() {
    return (
        <View
            style={{
                flexGrow: 1,
                justifyContent: 'center',
                alignItems: 'center',
            }}
        >
            <View
                style={{
                    width: 250,
                    height: 250,
                    padding: 50,
                    backgroundColor: '#000000',
                }}
            >
                <RoundedView
                    style={{
                        flexGrow: 1,
                        alignSelf: 'stretch',
                        justifyContent: 'center',
                        alignItems: 'center',
                        backgroundColor: '#ffffff',
                    }}
                    radius={50}
                >
                    <Text>hello world</Text>
                </RoundedView>
            </View>
        </View>
    );
}
1.1.0

1 year 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