Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1125 from glouvigny/glouvigny/hud-convo-search
feat: typehead go to conversation using cmd+K
- Loading branch information
Showing
11 changed files
with
488 additions
and
89 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
175 changes: 100 additions & 75 deletions
175
client/react-native/common/components/Library/ModalScreen.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 |
---|---|---|
@@ -1,102 +1,127 @@ | ||
import { StackActions, withNavigation } from 'react-navigation' | ||
import { View } from 'react-native' | ||
import { | ||
View, | ||
Platform, | ||
TouchableOpacity, | ||
} from 'react-native' | ||
import React from 'react' | ||
|
||
import Loader from './Loader' | ||
import Button from './Button' | ||
import colors from '../../constants/colors' | ||
|
||
const ModalScreen = props => { | ||
const { | ||
children, | ||
navigation, | ||
loading, | ||
showDismiss, | ||
width, | ||
footer, | ||
...otherProps | ||
} = props | ||
class ModalScreen extends React.PureComponent { | ||
componentDidMount () { | ||
if (Platform.OS === 'web') { | ||
if (this._keyboardListener === undefined) { | ||
this._keyboardListener = (e) => this.keyboardListener(e) | ||
} | ||
window.addEventListener('keyup', this._keyboardListener) | ||
} | ||
} | ||
|
||
const beforeDismiss = navigation.getParam('beforeDismiss') | ||
componentWillUnmount () { | ||
window.removeEventListener('keyup', this._keyboardListener) | ||
} | ||
|
||
return ( | ||
<> | ||
<View | ||
style={{ | ||
keyboardListener (event) { | ||
if ((this.props.showDismiss || this.props.keyboardDismiss) && event.key === 'Escape') { | ||
this.dismiss() | ||
} | ||
} | ||
|
||
render = () => { | ||
const { | ||
children, | ||
loading, | ||
showDismiss, | ||
width, | ||
footer, | ||
...otherProps | ||
} = this.props | ||
|
||
return ( | ||
<> | ||
<TouchableOpacity style={{ | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
zIndex: -1, | ||
}} | ||
> | ||
<View | ||
style={{ | ||
backgroundColor: colors.transparentGrey, | ||
flex: 1, | ||
}} | ||
/> | ||
</View> | ||
{!loading ? ( | ||
<View | ||
style={{ | ||
width: width || 320, | ||
position: 'absolute', | ||
flex: 1, | ||
}} | ||
> | ||
}} onPress={() => (this.props.showDismiss || this.props.keyboardDismiss) && this.dismiss()}> | ||
<View | ||
style={[ | ||
{ | ||
backgroundColor: colors.white, | ||
borderRadius: 10, | ||
}, | ||
]} | ||
{...otherProps} | ||
style={{ | ||
backgroundColor: this.props.backgroundColor || colors.transparentGrey, | ||
flex: 1, | ||
}} | ||
/> | ||
</TouchableOpacity> | ||
{!loading ? ( | ||
<View | ||
style={{ | ||
width: width || 320, | ||
position: 'absolute', | ||
flex: 1, | ||
}} | ||
> | ||
{showDismiss ? ( | ||
<View | ||
style={[ | ||
{ | ||
backgroundColor: colors.white, | ||
borderRadius: 10, | ||
}, | ||
]} | ||
{...otherProps} | ||
> | ||
{showDismiss ? ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
marginTop: 10, | ||
marginRight: 10, | ||
alignSelf: 'flex-end', | ||
zIndex: 1, | ||
}} | ||
> | ||
<Button | ||
onPress={() => this.dismiss()} | ||
icon={'x'} | ||
color={colors.fakeBlack} | ||
large | ||
/> | ||
</View> | ||
) : null} | ||
<View | ||
style={{ | ||
flex: 1, | ||
marginTop: 10, | ||
marginRight: 10, | ||
alignSelf: 'flex-end', | ||
zIndex: 1, | ||
marginTop: -24, | ||
}} | ||
> | ||
<Button | ||
onPress={() => { | ||
if (beforeDismiss !== undefined) { | ||
beforeDismiss() | ||
} | ||
|
||
navigation.dispatch( | ||
StackActions.pop({ | ||
n: 1, | ||
}) | ||
) | ||
}} | ||
icon={'x'} | ||
color={colors.fakeBlack} | ||
large | ||
/> | ||
{children} | ||
</View> | ||
) : null} | ||
<View | ||
style={{ | ||
marginTop: -24, | ||
}} | ||
> | ||
{children} | ||
</View> | ||
{footer} | ||
</View> | ||
{footer} | ||
</View> | ||
) : null} | ||
{loading && <Loader />} | ||
</> | ||
) | ||
) : null} | ||
{loading && <Loader />} | ||
</> | ||
) | ||
} | ||
|
||
dismiss () { | ||
const { navigation } = this.props | ||
const beforeDismiss = navigation.getParam('beforeDismiss') | ||
|
||
if (beforeDismiss !== undefined) { | ||
beforeDismiss() | ||
} | ||
|
||
navigation.dispatch( | ||
StackActions.pop({ | ||
n: 1, | ||
}) | ||
) | ||
} | ||
} | ||
|
||
export default withNavigation(ModalScreen) |
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
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
Oops, something went wrong.