Open
Description
Considered this component having a variant
prop with values white
and primary
, affecting the selection of the styles object:
import React, { FC } from 'react';
import {
StyleSheet, KeyboardAvoidingView, Platform, View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { colors } from '@company/design';
import Constants from 'expo-constants';
interface Props {
logonScreen?: boolean;
variant?: 'white' | 'primary';
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: colors.white,
},
safeAreaLogon: {
backgroundColor: 'white',
},
container: {
flex: 1,
},
center: {
justifyContent: 'center',
},
});
const variants = {
white: StyleSheet.create({
container: {
backgroundColor: 'white',
},
}),
primary: StyleSheet.create({
container: {
backgroundColor: colors.primary,
},
}),
};
export const ScreenWrapper: FC<Props> = ({
logonScreen, children, variant,
}) => {
const variantStyle = variants[variant || 'white'];
const viewStyle = [
styles.container,
variantStyle.container,
...logonScreen ? [styles.center] : [],
];
return (
<SafeAreaView
style={[
styles.safeArea,
...logonScreen ? [styles.safeAreaLogon] : [],
]}
>
<View style={viewStyle}>
{
Platform.OS === 'ios'
? (
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior="padding"
keyboardVerticalOffset={Constants.statusBarHeight}
>
{children}
</KeyboardAvoidingView>
)
: children
}
</View>
</SafeAreaView>
);
};
export default null;
ESlint will complain with the following:
error Unused style detected: undefined.container react-native/no-unused-styles
Maybe related to #125.
Metadata
Metadata
Assignees
Labels
No labels