diff --git a/react/features/base/react/components/native/SideBar.js b/react/features/base/react/components/native/SideBar.js index 9f2656ff4..9c082af9c 100644 --- a/react/features/base/react/components/native/SideBar.js +++ b/react/features/base/react/components/native/SideBar.js @@ -1,9 +1,8 @@ // @flow -import React, { Component } from 'react'; +import React, { Component, type Node } from 'react'; import { Animated, - Dimensions, TouchableWithoutFeedback, View } from 'react-native'; @@ -15,15 +14,10 @@ import styles, { SIDEBAR_WIDTH } from './styles'; */ type Props = { - /** - * The local participant's avatar - */ - _avatar: string, - /** * The children of the Component */ - children: React$Node, + children: Node, /** * Callback to notify the containing Component that the sidebar is @@ -47,11 +41,6 @@ type State = { */ showOverlay: boolean, - /** - * Indicates whether the side bar is visible or not. - */ - showSideBar: boolean, - /** * The native animation object. */ @@ -62,8 +51,6 @@ type State = { * A generic animated side bar to be used for left side menus */ export default class SideBar extends Component { - _mounted: boolean; - /** * Initializes a new {@code SideBar} instance. * @@ -74,15 +61,10 @@ export default class SideBar extends Component { this.state = { showOverlay: false, - showSideBar: false, - sliderAnimation: new Animated.Value(-SIDEBAR_WIDTH) + sliderAnimation: new Animated.Value(0) }; - this._getContainerStyle = this._getContainerStyle.bind(this); this._onHideMenu = this._onHideMenu.bind(this); - this._setShow = this._setShow.bind(this); - - this._setShow(props.show); } /** @@ -91,7 +73,7 @@ export default class SideBar extends Component { * @inheritdoc */ componentDidMount() { - this._mounted = true; + this._setShow(this.props.show); } /** @@ -112,42 +94,37 @@ export default class SideBar extends Component { */ render() { return ( - - - { - this.props.children - } - - - - - + + { + this.state.showOverlay + && + + + } + + { this.props.children } + + ); } - _getContainerStyle: () => Array + _getContentStyle: () => Array; /** - * Assembles a style array for the container. + * Assembles a style array for the sidebar content. * * @private * @returns {Array} */ - _getContainerStyle() { + _getContentStyle() { const { sliderAnimation } = this.state; - const { height, width } = Dimensions.get('window'); + const transformStyle + = { transform: [ { translateX: sliderAnimation } ] }; - return [ - styles.sideMenuContainer, - { - left: sliderAnimation, - width: this.state.showOverlay - ? Math.max(height, width) + SIDEBAR_WIDTH : SIDEBAR_WIDTH - } - ]; + return [ styles.sideMenuContent, transformStyle ]; } _onHideMenu: () => void; @@ -163,9 +140,7 @@ export default class SideBar extends Component { const { onHide } = this.props; - if (typeof onHide === 'function') { - onHide(); - } + onHide && onHide(); } _setShow: (boolean) => void; @@ -178,30 +153,21 @@ export default class SideBar extends Component { * @returns {void} */ _setShow(show) { - if (this.state.showSideBar !== show) { - if (show) { - this.setState({ - showOverlay: true - }); - } - - Animated - .timing( - this.state.sliderAnimation, - { toValue: show ? 0 : -SIDEBAR_WIDTH }) - .start(animationState => { - if (animationState.finished && !show) { - this.setState({ - showOverlay: false - }); - } - }); + if (show) { + this.setState({ showOverlay: true }); } - if (this._mounted) { - this.setState({ - showSideBar: show + Animated + .timing( + this.state.sliderAnimation, + { + toValue: show ? SIDEBAR_WIDTH : 0, + useNativeDriver: true + }) + .start(animationState => { + if (animationState.finished && !show) { + this.setState({ showOverlay: false }); + } }); - } } } diff --git a/react/features/base/react/components/native/styles.js b/react/features/base/react/components/native/styles.js index ae0d35f49..33510f6c9 100644 --- a/react/features/base/react/components/native/styles.js +++ b/react/features/base/react/components/native/styles.js @@ -278,8 +278,14 @@ const SIDEBAR_STYLES = { * The topmost container of the side bar. */ sideMenuContainer: { + ...StyleSheet.absoluteFillObject + }, + + /** + * The container of the actual content of the side menu. + */ + sideMenuContent: { bottom: 0, - flexDirection: 'row', left: -SIDEBAR_WIDTH, position: 'absolute', top: 0, @@ -287,27 +293,12 @@ const SIDEBAR_STYLES = { }, /** - * The container of the actual content of the side menu. - */ - sideMenuContent: { - width: SIDEBAR_WIDTH - }, - - /** - * The opaque area that covers the rest of the scren, when + * The opaque area that covers the rest of the screen, when * the side bar is open. */ sideMenuShadow: { - backgroundColor: 'rgba(0, 0, 0, 0.5)', - flex: 1 - }, - - /** - * The touchable area of the rest of the screen that closes the side bar - * when tapped. - */ - sideMenuShadowTouchable: { - flex: 1 + ...StyleSheet.absoluteFillObject, + backgroundColor: 'rgba(0, 0, 0, 0.5)' } };