Skip to content

Commit

Permalink
fix(rn): crash handler
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Nov 13, 2018
1 parent 115347d commit 93109c7
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 76 deletions.
71 changes: 46 additions & 25 deletions client/react-native/common/components/Library/Filters.js
Expand Up @@ -34,33 +34,54 @@ export class FilterModal extends React.Component {
}

close = () => {
this.props.navigation.dispatch(StackActions.pop({
n: 1,
}))
this.props.navigation.dispatch(
StackActions.pop({
n: 1,
})
)
}

render = () => <ModalScreen navigation={this.props.navigation}>
<Rows style={[padding]} align='center'>
{this.props.title ? <Text>{this.props.title}</Text> : null}
{React.Children.map(this.props.children, child => React.cloneElement(child, {
onChange: value => this.setState({ [child.props.name]: value }),
value: this.state[child.props.name],
}))}
<Cols>
<Button onPress={() => this.onDismiss()} icon={'x-circle'}
style={{ backgroundColor: colors.red }}>Cancel</Button>
<Button onPress={() => this.onFilter()} icon={'filter'}>Filter</Button>
</Cols>
</Rows>
</ModalScreen>
render () {
return (
<ModalScreen navigation={this.props.navigation}>
<Rows style={[padding]} align='center'>
{this.props.title ? <Text>{this.props.title}</Text> : null}
{React.Children.map(this.props.children, child =>
React.cloneElement(child, {
onChange: value => this.setState({ [child.props.name]: value }),
value: this.state[child.props.name],
})
)}
<Cols>
<Button
onPress={() => this.onDismiss()}
icon={'x-circle'}
style={{ backgroundColor: colors.red }}
>
Cancel
</Button>
<Button onPress={() => this.onFilter()} icon={'filter'}>
Filter
</Button>
</Cols>
</Rows>
</ModalScreen>
)
}
}

// Impl for this is really bad, move to radio buttons instead
export const PickerFilter = ({ value, onChange, choices }) => <Rows style={{ flex: 1, width: '100%' }}>
{choices.map(({ value: choiceValue, label }) =>
<Cols size={1} key={choiceValue}>
<Switch value={value === choiceValue} onValueChange={() => onChange(choiceValue)} style={{ width: 50 }} />
<FlexText>{label}</FlexText>
</Cols>,
)}
</Rows>
export const PickerFilter = ({ value, onChange, choices }) => (
<Rows style={{ flex: 1, width: '100%' }}>
{choices.map(({ value: choiceValue, label }) => (
<Cols size={1} key={choiceValue}>
<Switch
value={value === choiceValue}
onValueChange={() => onChange(choiceValue)}
style={{ width: 50 }}
/>
<FlexText>{label}</FlexText>
</Cols>
))}
</Rows>
)
@@ -1,10 +1,13 @@
import React, { PureComponent } from 'react'
import { Platform, ActivityIndicator, Share } from 'react-native'
import {
Platform,
ActivityIndicator,
Share,
} from 'react-native'
import { Flex, Screen, Button, Text, ModalScreen, TextInputMultilineFix } from '../../../Library'
Flex,
Screen,
Button,
Text,
ModalScreen,
TextInputMultilineFix,
} from '../../../Library'
import { colors } from '../../../../constants'
import {
padding,
Expand Down Expand Up @@ -37,33 +40,39 @@ const requestContact = async (contactId, navigation, errorHandler) => {
}
}

const ActionButton = props => <Button
icon={props.icon}
background={colors.blue}
margin
padding
rounded={23}
height={24}
medium
middle
center
self='stretch'
onPress={props.onPress}
>
{props.label}
</Button>

const AddButton = ({ contactId, navigation, errorHandler }) => <ActionButton
icon='plus'
onPress={() => requestContact(contactId, navigation, errorHandler)}
label={'Add this key'}
/>

const ShareMyKey = ({ contactId }) => <ActionButton
icon='plus'
onPress={() => Share.share({ message: contactId }).catch(() => null)}
label={'Share my key'}
/>
const ActionButton = props => (
<Button
icon={props.icon}
background={colors.blue}
margin
padding
rounded={23}
height={24}
medium
middle
center
self='stretch'
onPress={props.onPress}
>
{props.label}
</Button>
)

const AddButton = ({ contactId, navigation, errorHandler }) => (
<ActionButton
icon='plus'
onPress={() => requestContact(contactId, navigation, errorHandler)}
label={'Add this key'}
/>
)

const ShareMyKey = ({ contactId }) => (
<ActionButton
icon='plus'
onPress={() => Share.share({ message: contactId }).catch(() => null)}
label={'Share my key'}
/>
)

class ByPublicKeyComponent extends PureComponent {
state = {
Expand Down Expand Up @@ -115,13 +124,16 @@ class ByPublicKeyComponent extends PureComponent {

<Flex.Cols justify='center'>
{shareButton ? <ShareMyKey contactId={contactId} /> : null}
{addButton ? <AddButton
contactId={contactId}
navigation={navigation}
errorHandler={err => {
this.setState({ err })
console.error(err)
}} /> : null}
{addButton ? (
<AddButton
contactId={contactId}
navigation={navigation}
errorHandler={err => {
this.setState({ err })
console.error(err)
}}
/>
) : null}
</Flex.Cols>
</Flex.Rows>
)
Expand All @@ -130,13 +142,15 @@ class ByPublicKeyComponent extends PureComponent {

const ByPublicKey = fragments.Contact(ByPublicKeyComponent)

const AddByPublicKeyScreen = props => <Screen style={[{ backgroundColor: colors.white }, paddingVertical]}>
<ByPublicKeyComponent
navigation={props.navigation}
initialKey={''}
addButton
/>
</Screen>
const AddByPublicKeyScreen = props => (
<Screen style={[{ backgroundColor: colors.white }, paddingVertical]}>
<ByPublicKeyComponent
navigation={props.navigation}
initialKey={''}
addButton
/>
</Screen>
)

class SharePublicKeyScreen extends PureComponent {
render () {
Expand Down Expand Up @@ -218,9 +232,15 @@ export default createTabNavigator(
borderBottom,
],
},
},
}
)

export const ByPublicKeyModal = props => <ModalScreen navigation={props.navigation}>
<ByPublicKeyComponent addButton initialKey={props.navigation.getParam('initialKey', '')} {...props} />
</ModalScreen>
export const ByPublicKeyModal = props => (
<ModalScreen navigation={props.navigation}>
<ByPublicKeyComponent
addButton
initialKey={props.navigation.getParam('initialKey', '')}
{...props}
/>
</ModalScreen>
)
2 changes: 1 addition & 1 deletion client/react-native/common/helpers/crash-handler.js
Expand Up @@ -27,7 +27,7 @@ if (Platform.OS === 'ios' || Platform.OS === 'android') {
{ cancelable: false }
)
}
const allowInDevMode = true
const allowInDevMode = false
const forceAppQuit = false
const executeDefaultHandler = false

Expand Down

0 comments on commit 93109c7

Please sign in to comment.