You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BottomSheet.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import React, { PureComponent, type Node } from 'react';
  3. import { SafeAreaView, View } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../../color-scheme';
  5. import { SlidingView } from '../../../react';
  6. import { connect } from '../../../redux';
  7. import { StyleType } from '../../../styles';
  8. import { bottomSheetStyles as styles } from './styles';
  9. /**
  10. * The type of {@code BottomSheet}'s React {@code Component} prop types.
  11. */
  12. type Props = {
  13. /**
  14. * The color-schemed stylesheet of the feature.
  15. */
  16. _styles: StyleType,
  17. /**
  18. * The children to be displayed within this component.
  19. */
  20. children: Node,
  21. /**
  22. * Handler for the cancel event, which happens when the user dismisses
  23. * the sheet.
  24. */
  25. onCancel: ?Function
  26. };
  27. /**
  28. * A component emulating Android's BottomSheet.
  29. */
  30. class BottomSheet extends PureComponent<Props> {
  31. /**
  32. * Assembles a style for the BottomSheet container.
  33. *
  34. * @private
  35. * @returns {StyleType}
  36. */
  37. _getContainerStyle() {
  38. const { _styles } = this.props;
  39. return {
  40. ...styles.container,
  41. backgroundColor: _styles.sheet.backgroundColor
  42. };
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {ReactElement}
  49. */
  50. render() {
  51. const { _styles } = this.props;
  52. return (
  53. <SlidingView
  54. onHide = { this.props.onCancel }
  55. position = 'bottom'
  56. show = { true }>
  57. <SafeAreaView
  58. style = { this._getContainerStyle() }>
  59. <View style = { _styles.sheet }>
  60. { this.props.children }
  61. </View>
  62. </SafeAreaView>
  63. </SlidingView>
  64. );
  65. }
  66. }
  67. /**
  68. * Maps part of the Redux state to the props of this component.
  69. *
  70. * @param {Object} state - The Redux state.
  71. * @returns {{
  72. * _styles: StyleType
  73. * }}
  74. */
  75. function _mapStateToProps(state) {
  76. return {
  77. _styles: ColorSchemeRegistry.get(state, 'BottomSheet')
  78. };
  79. }
  80. export default connect(_mapStateToProps)(BottomSheet);