-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mobile bottom sheet component (#13612)
* rnmobile: Implement image settings button using InspectorControls.Slot pattern. * rnmobile: Add missing semicolon * rnmobile: Adding bottom-sheet component to mobile * rnmobile: Styling bottom-sheet header * rnmobile: Bottom-sheet clean up * rnmobile: Fix lint issues on bottom-sheet related code. * rnmobile: Fix small lint issues * rnmobile: Move inline toolbar button definition out of constant. * rnmobile: Remove extra white-spaces * revert package-lock.json changes * rnmobile: Fix merge issue * rnmobile: exporting component BottomSheet.Button to be used as bottom-sheet header buttons * rnmobile: Adding BottomSheet.Cell component as an extraction for BottomSheet users. * Fix lint issues * Reverting changes to package-lock.json * Fix merge issues
- Loading branch information
1 parent
cca1364
commit 19ac5bb
Showing
6 changed files
with
256 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/editor/src/components/mobile/bottom-sheet/button.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TouchableOpacity, View, Text } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
export default function Button( props ) { | ||
const { | ||
onPress, | ||
disabled, | ||
text, | ||
color, | ||
} = props; | ||
|
||
return ( | ||
<TouchableOpacity | ||
accessible={ true } | ||
onPress={ onPress } | ||
disabled={ disabled } | ||
> | ||
<View style={ { flexDirection: 'row', justifyContent: 'center' } }> | ||
<Text style={ { ...styles.buttonText, color } }> | ||
{ text } | ||
</Text> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/editor/src/components/mobile/bottom-sheet/cell.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TouchableOpacity, Text } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
export default function Cell( props ) { | ||
const { | ||
onPress, | ||
label, | ||
value, | ||
} = props; | ||
|
||
return ( | ||
<TouchableOpacity style={ styles.cellContainer } onPress={ onPress }> | ||
<Text style={ styles.cellLabel }>{ label }</Text> | ||
<Text style={ styles.cellValue }>{ value }</Text> | ||
</TouchableOpacity> | ||
); | ||
} |
90 changes: 90 additions & 0 deletions
90
packages/editor/src/components/mobile/bottom-sheet/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Text, View } from 'react-native'; | ||
import Modal from 'react-native-modal'; | ||
import SafeArea from 'react-native-safe-area'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
import Button from './button'; | ||
import Cell from './cell'; | ||
|
||
class BottomSheet extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.onSafeAreaInsetsUpdate = this.onSafeAreaInsetsUpdate.bind( this ); | ||
this.state = { | ||
safeAreaBottomInset: 0, | ||
}; | ||
|
||
SafeArea.getSafeAreaInsetsForRootView().then( this.onSafeAreaInsetsUpdate ); | ||
} | ||
|
||
componentDidMount() { | ||
SafeArea.addEventListener( 'safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsUpdate ); | ||
} | ||
|
||
componentWillUnmount() { | ||
SafeArea.removeEventListener( 'safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsUpdate ); | ||
} | ||
|
||
onSafeAreaInsetsUpdate( result ) { | ||
const { safeAreaInsets } = result; | ||
if ( this.state.safeAreaBottomInset !== safeAreaInsets.bottom ) { | ||
this.setState( { safeAreaBottomInset: safeAreaInsets.bottom } ); | ||
} | ||
} | ||
|
||
render() { | ||
const { isVisible, leftButton, rightButton } = this.props; | ||
|
||
return ( | ||
<Modal | ||
isVisible={ isVisible } | ||
style={ styles.bottomModal } | ||
animationInTiming={ 500 } | ||
animationOutTiming={ 500 } | ||
backdropTransitionInTiming={ 500 } | ||
backdropTransitionOutTiming={ 500 } | ||
onBackdropPress={ this.props.onClose } | ||
onSwipe={ this.props.onClose } | ||
swipeDirection="down" | ||
> | ||
<View style={ { ...styles.content, borderColor: 'rgba(0, 0, 0, 0.1)' } }> | ||
<View style={ styles.dragIndicator } /> | ||
<View style={ styles.head }> | ||
<View style={ { flex: 1 } }> | ||
{ leftButton } | ||
</View> | ||
<View style={ styles.titleContainer }> | ||
<Text style={ styles.title }> | ||
{ this.props.title } | ||
</Text> | ||
</View> | ||
<View style={ { flex: 1 } }> | ||
{ rightButton } | ||
</View> | ||
</View> | ||
|
||
<View style={ styles.separator } /> | ||
{ this.props.children } | ||
<View style={ { flexGrow: 1 } }></View> | ||
<View style={ { height: this.state.safeAreaBottomInset } } /> | ||
</View> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
BottomSheet.Button = Button; | ||
BottomSheet.Cell = Cell; | ||
|
||
export default BottomSheet; |
82 changes: 82 additions & 0 deletions
82
packages/editor/src/components/mobile/bottom-sheet/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//Bottom Sheet | ||
|
||
.bottomModal { | ||
justify-content: flex-end; | ||
margin: 0; | ||
} | ||
|
||
.dragIndicator { | ||
background-color: $light-gray-400; | ||
height: 4px; | ||
width: 10%; | ||
top: -12px; | ||
margin: auto; | ||
border-radius: 2px; | ||
} | ||
|
||
.separator { | ||
background-color: $light-gray-400; | ||
height: 1px; | ||
width: 100%; | ||
margin: auto; | ||
} | ||
|
||
.content { | ||
background-color: $white; | ||
padding: 18px 10px 5px 10px; | ||
justify-content: center; | ||
border-top-right-radius: 8px; | ||
border-top-left-radius: 8px; | ||
} | ||
|
||
.head { | ||
flex-direction: row; | ||
width: 100%; | ||
margin-bottom: 5px; | ||
justify-content: space-between; | ||
align-items: center; | ||
align-content: center; | ||
} | ||
|
||
.title { | ||
color: $dark-gray-600; | ||
font-size: 18px; | ||
font-weight: 600; | ||
text-align: center; | ||
} | ||
|
||
.titleContainer { | ||
justify-content: center; | ||
flex: 2; | ||
align-content: center; | ||
} | ||
|
||
// Button | ||
|
||
.buttonText { | ||
font-size: 18px; | ||
padding: 5px; | ||
} | ||
|
||
// Cell | ||
|
||
//Bottom Sheet | ||
|
||
.cellContainer { | ||
flex-direction: row; | ||
min-height: 50; | ||
justify-content: space-between; | ||
padding-left: 12; | ||
padding-right: 12; | ||
align-items: center; | ||
} | ||
|
||
.cellLabel { | ||
font-size: 18px; | ||
color: #000; | ||
} | ||
|
||
.cellValue { | ||
font-size: 18px; | ||
color: $dark-gray-400; | ||
} |