fix: iOS 10 bottom sheet style

This commit is contained in:
Bettenbuk Zoltan 2019-05-24 09:24:47 +02:00 committed by Saúl Ibarra Corretgé
parent 1bc28e4904
commit d387cbe5bd
2 changed files with 51 additions and 32 deletions

View File

@ -1,7 +1,7 @@
// @flow // @flow
import React, { PureComponent, type Node } from 'react'; import React, { PureComponent, type Node } from 'react';
import { SafeAreaView, View } from 'react-native'; import { Platform, SafeAreaView, View } from 'react-native';
import { ColorSchemeRegistry } from '../../../color-scheme'; import { ColorSchemeRegistry } from '../../../color-scheme';
import { SlidingView } from '../../../react'; import { SlidingView } from '../../../react';
@ -36,21 +36,6 @@ type Props = {
* A component emulating Android's BottomSheet. * A component emulating Android's BottomSheet.
*/ */
class BottomSheet extends PureComponent<Props> { class BottomSheet extends PureComponent<Props> {
/**
* Assembles a style for the BottomSheet container.
*
* @private
* @returns {StyleType}
*/
_getContainerStyle() {
const { _styles } = this.props;
return {
...styles.container,
backgroundColor: _styles.sheet.backgroundColor
};
}
/** /**
* Implements React's {@link Component#render()}. * Implements React's {@link Component#render()}.
* *
@ -65,15 +50,44 @@ class BottomSheet extends PureComponent<Props> {
onHide = { this.props.onCancel } onHide = { this.props.onCancel }
position = 'bottom' position = 'bottom'
show = { true }> show = { true }>
<SafeAreaView <View
style = { this._getContainerStyle() }> pointerEvents = 'box-none'
<View style = { _styles.sheet }> style = { styles.sheetContainer }>
{ this.props.children } <View
pointerEvents = 'box-none'
style = { styles.sheetAreaCover } />
<View
style = { [
styles.sheetItemContainer,
_styles.sheet
] }>
{ this._getWrappedContent() }
</View> </View>
</SafeAreaView> </View>
</SlidingView> </SlidingView>
); );
} }
/**
* Wraps the content when needed (iOS 11 and above), or just returns the original children.
*
* @returns {React$Element}
*/
_getWrappedContent() {
if (Platform.OS === 'ios') {
const majorVersionIOS = parseInt(Platform.Version, 10);
if (majorVersionIOS > 10) {
return (
<SafeAreaView>
{ this.props.children }
</SafeAreaView>
);
}
}
return this.props.children;
}
} }
/** /**

View File

@ -27,17 +27,25 @@ export const PLACEHOLDER_COLOR = ColorPalette.lightGrey;
* been implemented as per the Material Design guidelines: * been implemented as per the Material Design guidelines:
* {@link https://material.io/guidelines/components/bottom-sheets.html}. * {@link https://material.io/guidelines/components/bottom-sheets.html}.
*/ */
export const bottomSheetStyles = createStyleSheet({ export const bottomSheetStyles = {
sheetAreaCover: {
backgroundColor: ColorPalette.transparent,
flex: 1
},
/** /**
* Style for the container of the sheet. * Style for the container of the sheet.
*/ */
container: { sheetContainer: {
bottom: 0, alignContent: 'stretch',
left: 0, flex: 1,
position: 'absolute', flexDirection: 'column'
right: 0 },
sheetItemContainer: {
paddingHorizontal: MD_ITEM_MARGIN_PADDING
} }
}); };
export const brandedDialog = createStyleSheet({ export const brandedDialog = createStyleSheet({
@ -137,10 +145,7 @@ ColorSchemeRegistry.register('BottomSheet', {
* Bottom sheet's base style. * Bottom sheet's base style.
*/ */
sheet: { sheet: {
backgroundColor: schemeColor('background'), backgroundColor: schemeColor('background')
flex: 1,
paddingHorizontal: MD_ITEM_MARGIN_PADDING,
paddingVertical: 8
}, },
/** /**