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.native.js 2.2KB

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