您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BottomSheet.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // @flow
  2. import React, { PureComponent, type Node } from 'react';
  3. import { SafeAreaView, ScrollView, 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. * Function to render a bottom sheet header element, if necessary.
  28. */
  29. renderHeader: ?Function
  30. };
  31. /**
  32. * A component emulating Android's BottomSheet.
  33. */
  34. class BottomSheet extends PureComponent<Props> {
  35. /**
  36. * Implements React's {@link Component#render()}.
  37. *
  38. * @inheritdoc
  39. * @returns {ReactElement}
  40. */
  41. render() {
  42. const { _styles, renderHeader } = this.props;
  43. return (
  44. <SlidingView
  45. onHide = { this.props.onCancel }
  46. position = 'bottom'
  47. show = { true }>
  48. <View
  49. pointerEvents = 'box-none'
  50. style = { styles.sheetContainer }>
  51. <View
  52. pointerEvents = 'box-none'
  53. style = { styles.sheetAreaCover } />
  54. { renderHeader && renderHeader() }
  55. <SafeAreaView
  56. style = { [
  57. styles.sheetItemContainer,
  58. _styles.sheet
  59. ] }>
  60. <ScrollView
  61. bounces = { false }
  62. showsVerticalScrollIndicator = { false }
  63. style = { styles.scrollView } >
  64. { this.props.children }
  65. </ScrollView>
  66. </SafeAreaView>
  67. </View>
  68. </SlidingView>
  69. );
  70. }
  71. }
  72. /**
  73. * Maps part of the Redux state to the props of this component.
  74. *
  75. * @param {Object} state - The Redux state.
  76. * @returns {{
  77. * _styles: StyleType
  78. * }}
  79. */
  80. function _mapStateToProps(state) {
  81. return {
  82. _styles: ColorSchemeRegistry.get(state, 'BottomSheet')
  83. };
  84. }
  85. export default connect(_mapStateToProps)(BottomSheet);