2018-05-07 20:55:17 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-04-24 11:05:14 +00:00
|
|
|
import React, { PureComponent, type Node } from 'react';
|
2019-05-24 11:39:41 +00:00
|
|
|
import { Platform, SafeAreaView, ScrollView, View } from 'react-native';
|
2019-01-09 16:58:29 +00:00
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
import { ColorSchemeRegistry } from '../../../color-scheme';
|
2019-04-24 11:05:14 +00:00
|
|
|
import { SlidingView } from '../../../react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../redux';
|
2019-01-22 10:35:28 +00:00
|
|
|
import { StyleType } from '../../../styles';
|
2018-05-07 20:55:17 +00:00
|
|
|
|
|
|
|
import { bottomSheetStyles as styles } from './styles';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of {@code BottomSheet}'s React {@code Component} prop types.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the feature.
|
|
|
|
*/
|
|
|
|
_styles: StyleType,
|
|
|
|
|
2018-05-07 20:55:17 +00:00
|
|
|
/**
|
|
|
|
* The children to be displayed within this component.
|
|
|
|
*/
|
|
|
|
children: Node,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the cancel event, which happens when the user dismisses
|
|
|
|
* the sheet.
|
|
|
|
*/
|
|
|
|
onCancel: ?Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-04-24 11:05:14 +00:00
|
|
|
* A component emulating Android's BottomSheet.
|
2018-05-07 20:55:17 +00:00
|
|
|
*/
|
2019-04-24 11:05:14 +00:00
|
|
|
class BottomSheet extends PureComponent<Props> {
|
2018-05-07 20:55:17 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _styles } = this.props;
|
|
|
|
|
2019-04-24 11:05:14 +00:00
|
|
|
return (
|
|
|
|
<SlidingView
|
|
|
|
onHide = { this.props.onCancel }
|
|
|
|
position = 'bottom'
|
|
|
|
show = { true }>
|
2019-05-24 07:24:47 +00:00
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.sheetContainer }>
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.sheetAreaCover } />
|
|
|
|
<View
|
|
|
|
style = { [
|
|
|
|
styles.sheetItemContainer,
|
|
|
|
_styles.sheet
|
|
|
|
] }>
|
2019-06-12 14:54:28 +00:00
|
|
|
<ScrollView
|
|
|
|
bounces = { false }
|
|
|
|
showsVerticalScrollIndicator = { false }>
|
2019-05-24 11:39:41 +00:00
|
|
|
{ this._getWrappedContent() }
|
|
|
|
</ScrollView>
|
2018-05-07 20:55:17 +00:00
|
|
|
</View>
|
2019-05-24 07:24:47 +00:00
|
|
|
</View>
|
2019-04-24 11:05:14 +00:00
|
|
|
</SlidingView>
|
|
|
|
);
|
2018-05-07 20:55:17 +00:00
|
|
|
}
|
2019-05-24 07:24:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2018-05-07 20:55:17 +00:00
|
|
|
}
|
2019-01-22 10:35:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {{
|
|
|
|
* _styles: StyleType
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
_styles: ColorSchemeRegistry.get(state, 'BottomSheet')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(BottomSheet);
|