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

BottomSheet.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import React, { Component, type Node } from 'react';
  3. import { TouchableWithoutFeedback, View } from 'react-native';
  4. import { Modal } from '../../../react';
  5. import { bottomSheetStyles as styles } from './styles';
  6. /**
  7. * The type of {@code BottomSheet}'s React {@code Component} prop types.
  8. */
  9. type Props = {
  10. /**
  11. * The children to be displayed within this component.
  12. */
  13. children: Node,
  14. /**
  15. * Handler for the cancel event, which happens when the user dismisses
  16. * the sheet.
  17. */
  18. onCancel: ?Function
  19. };
  20. /**
  21. * A component emulating Android's BottomSheet. For all intents and purposes,
  22. * this component has been designed to work and behave as a {@code Dialog}.
  23. */
  24. export default class BottomSheet extends Component<Props> {
  25. /**
  26. * Initializes a new {@code BottomSheet} instance.
  27. *
  28. * @inheritdoc
  29. */
  30. constructor(props: Props) {
  31. super(props);
  32. this._onCancel = this._onCancel.bind(this);
  33. }
  34. /**
  35. * Implements React's {@link Component#render()}.
  36. *
  37. * @inheritdoc
  38. * @returns {ReactElement}
  39. */
  40. render() {
  41. return [
  42. <View
  43. key = 'overlay'
  44. style = { styles.overlay } />,
  45. <Modal
  46. key = 'modal'
  47. onRequestClose = { this._onCancel }
  48. visible = { true }>
  49. <View style = { styles.container }>
  50. <TouchableWithoutFeedback
  51. onPress = { this._onCancel } >
  52. <View style = { styles.backdrop } />
  53. </TouchableWithoutFeedback>
  54. <View style = { styles.sheet }>
  55. { this.props.children }
  56. </View>
  57. </View>
  58. </Modal>
  59. ];
  60. }
  61. _onCancel: () => void;
  62. /**
  63. * Cancels the dialog by calling the onCancel prop callback.
  64. *
  65. * @private
  66. * @returns {void}
  67. */
  68. _onCancel() {
  69. const { onCancel } = this.props;
  70. onCancel && onCancel();
  71. }
  72. }