From 4fdd71d1bdabd2ac1216f6f74a53953bec29361b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 7 May 2018 22:55:17 +0200 Subject: [PATCH] [RN] Refactor SimpleBottomSheet Make it more generic by accepting any content except of just rows with text and icons. In addition, rework its structure so the animation is smoother, by putting the background overlay outside of the Modal. This way, the animation doesn't affect the background, which won't slide down. --- .../dialog/components/BottomSheet.native.js | 84 +++++++ ...eBottomSheet.web.js => BottomSheet.web.js} | 0 .../components/SimpleBottomSheet.native.js | 206 ------------------ .../features/base/dialog/components/index.js | 2 +- .../features/base/dialog/components/styles.js | 73 ++----- .../components/AudioRoutePickerDialog.js | 97 +++++++-- .../mobile/audio-mode/components/styles.js | 50 +++++ 7 files changed, 236 insertions(+), 276 deletions(-) create mode 100644 react/features/base/dialog/components/BottomSheet.native.js rename react/features/base/dialog/components/{SimpleBottomSheet.web.js => BottomSheet.web.js} (100%) delete mode 100644 react/features/base/dialog/components/SimpleBottomSheet.native.js create mode 100644 react/features/mobile/audio-mode/components/styles.js diff --git a/react/features/base/dialog/components/BottomSheet.native.js b/react/features/base/dialog/components/BottomSheet.native.js new file mode 100644 index 000000000..4b06fedb6 --- /dev/null +++ b/react/features/base/dialog/components/BottomSheet.native.js @@ -0,0 +1,84 @@ +// @flow + +import React, { Component, type Node } from 'react'; +import { Modal, TouchableWithoutFeedback, View } from 'react-native'; + +import { bottomSheetStyles as styles } from './styles'; + +/** + * The type of {@code BottomSheet}'s React {@code Component} prop types. + */ +type Props = { + + /** + * The children to be displayed within this component. + */ + children: Node, + + /** + * Handler for the cancel event, which happens when the user dismisses + * the sheet. + */ + onCancel: ?Function +}; + +/** + * A component emulating Android's BottomSheet. For all intents and purposes, + * this component has been designed to work and behave as a {@code Dialog}. + */ +export default class BottomSheet extends Component { + /** + * Initializes a new {@code BottomSheet} instance. + * + * @inheritdoc + */ + constructor(props: Props) { + super(props); + + this._onCancel = this._onCancel.bind(this); + } + + /** + * Implements React's {@link Component#render()}. + * + * @inheritdoc + * @returns {ReactElement} + */ + render() { + return [ + , + + + + + + + { this.props.children } + + + + ]; + } + + _onCancel: () => void; + + /** + * Cancels the dialog by calling the onCancel prop callback. + * + * @private + * @returns {void} + */ + _onCancel() { + const { onCancel } = this.props; + + onCancel && onCancel(); + } +} diff --git a/react/features/base/dialog/components/SimpleBottomSheet.web.js b/react/features/base/dialog/components/BottomSheet.web.js similarity index 100% rename from react/features/base/dialog/components/SimpleBottomSheet.web.js rename to react/features/base/dialog/components/BottomSheet.web.js diff --git a/react/features/base/dialog/components/SimpleBottomSheet.native.js b/react/features/base/dialog/components/SimpleBottomSheet.native.js deleted file mode 100644 index 73d4c2390..000000000 --- a/react/features/base/dialog/components/SimpleBottomSheet.native.js +++ /dev/null @@ -1,206 +0,0 @@ -// @flow - -import React, { Component } from 'react'; -import { - Modal, - Text, - TouchableHighlight, - TouchableWithoutFeedback, - View -} from 'react-native'; -import { connect } from 'react-redux'; - -import { Icon } from '../../font-icons'; - -import { simpleBottomSheet as styles } from './styles'; - -/** - * Underlay color for the buttons on the sheet. - * - * @type {string} - */ -const BUTTON_UNDERLAY_COLOR = '#eee'; - -type Option = { - - /** - * Name of the icon which will be rendered on the right. - */ - iconName: string, - - /** - * True if the element is selected (will be highlighted in blue), - * false otherwise. - */ - selected: boolean, - - /** - * Text which will be rendered in the row. - */ - text: string -}; - - -/** - * The type of {@code SimpleBottomSheet}'s React {@code Component} prop types. - */ -type Props = { - - /** - * Handler for the cancel event, which happens when the user dismisses - * the sheet. - */ - onCancel: Function, - - /** - * Handler for the event when an option has been selected in the sheet. - */ - onSubmit: Function, - - /** - * Array of options which will be rendered as rows. - */ - options: Array