2019-04-24 11:05:14 +00:00
|
|
|
import React, { PureComponent, type Node } from 'react';
|
2022-06-10 09:46:52 +00:00
|
|
|
import { SafeAreaView, ScrollView, View } from 'react-native';
|
2019-01-09 16:58:29 +00:00
|
|
|
|
2019-04-24 11:05:14 +00:00
|
|
|
import { SlidingView } from '../../../react';
|
2022-06-20 14:53:19 +00:00
|
|
|
import { connect } from '../../../redux';
|
|
|
|
import { hideSheet } from '../../actions';
|
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 = {
|
|
|
|
|
2021-06-03 16:23:18 +00:00
|
|
|
/**
|
|
|
|
* Whether to add padding to scroll view.
|
|
|
|
*/
|
|
|
|
addScrollViewPadding?: boolean,
|
|
|
|
|
2018-05-07 20:55:17 +00:00
|
|
|
/**
|
|
|
|
* The children to be displayed within this component.
|
|
|
|
*/
|
|
|
|
children: Node,
|
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
/**
|
|
|
|
* Redux Dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
2018-05-07 20:55:17 +00:00
|
|
|
/**
|
|
|
|
* Handler for the cancel event, which happens when the user dismisses
|
|
|
|
* the sheet.
|
|
|
|
*/
|
2019-11-25 12:01:54 +00:00
|
|
|
onCancel: ?Function,
|
|
|
|
|
2020-03-23 08:37:35 +00:00
|
|
|
/**
|
|
|
|
* Function to render a bottom sheet header element, if necessary.
|
|
|
|
*/
|
2021-07-13 06:50:08 +00:00
|
|
|
renderHeader: ?Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to render a bottom sheet footer element, if necessary.
|
|
|
|
*/
|
|
|
|
renderFooter: ?Function,
|
|
|
|
|
|
|
|
/**
|
2021-06-03 16:23:18 +00:00
|
|
|
* Whether to show sliding view or not.
|
|
|
|
*/
|
|
|
|
showSlidingView?: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The component's external style.
|
2021-06-03 16:23:18 +00:00
|
|
|
*/
|
|
|
|
style: Object
|
2018-05-07 20:55:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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> {
|
2021-06-03 16:23:18 +00:00
|
|
|
/**
|
|
|
|
* Default values for {@code BottomSheet} component's properties.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static defaultProps = {
|
|
|
|
addScrollViewPadding: true,
|
|
|
|
showSlidingView: true
|
|
|
|
};
|
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new instance with.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onCancel = this._onCancel.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the cancel event, when the user dismissed the sheet. By default we close it.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
|
|
|
if (this.props.onCancel) {
|
|
|
|
this.props.onCancel();
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(hideSheet());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 20:55:17 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2021-06-03 16:23:18 +00:00
|
|
|
const {
|
|
|
|
addScrollViewPadding,
|
|
|
|
renderHeader,
|
|
|
|
renderFooter,
|
|
|
|
showSlidingView,
|
|
|
|
style
|
|
|
|
} = this.props;
|
2019-01-22 10:35:28 +00:00
|
|
|
|
2019-04-24 11:05:14 +00:00
|
|
|
return (
|
|
|
|
<SlidingView
|
2020-04-10 13:07:48 +00:00
|
|
|
accessibilityRole = 'menu'
|
|
|
|
accessibilityViewIsModal = { true }
|
2022-06-20 14:53:19 +00:00
|
|
|
onHide = { this._onCancel }
|
2019-04-24 11:05:14 +00:00
|
|
|
position = 'bottom'
|
2021-06-03 16:23:18 +00:00
|
|
|
show = { showSlidingView }>
|
2019-05-24 07:24:47 +00:00
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.sheetContainer }>
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.sheetAreaCover } />
|
2020-03-23 08:37:35 +00:00
|
|
|
{ renderHeader && renderHeader() }
|
2019-11-25 12:01:54 +00:00
|
|
|
<SafeAreaView
|
2019-05-24 07:24:47 +00:00
|
|
|
style = { [
|
|
|
|
styles.sheetItemContainer,
|
2021-08-04 13:11:32 +00:00
|
|
|
renderHeader
|
2022-06-10 09:46:52 +00:00
|
|
|
? styles.sheetHeader
|
|
|
|
: styles.sheet,
|
|
|
|
renderFooter && styles.sheetFooter,
|
|
|
|
style
|
|
|
|
] }>
|
2019-11-25 12:01:54 +00:00
|
|
|
<ScrollView
|
|
|
|
bounces = { false }
|
|
|
|
showsVerticalScrollIndicator = { false }
|
2021-09-21 17:30:24 +00:00
|
|
|
style = { [
|
2022-06-10 09:46:52 +00:00
|
|
|
renderFooter && styles.sheet,
|
2021-09-21 17:30:24 +00:00
|
|
|
addScrollViewPadding && styles.scrollView
|
|
|
|
] } >
|
2019-11-25 12:01:54 +00:00
|
|
|
{ this.props.children }
|
|
|
|
</ScrollView>
|
2021-07-13 06:50:08 +00:00
|
|
|
{ renderFooter && renderFooter() }
|
2019-11-25 12:01:54 +00:00
|
|
|
</SafeAreaView>
|
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-01-22 10:35:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
export default connect()(BottomSheet);
|