Skip to content

Commit

Permalink
Clean up syntax
Browse files Browse the repository at this point in the history
I was pulling this in to experiment with and there were some issues:
- `TextInput` is never used.
- `componentDidMount` and `onClose` both need to use arrow functions to have `this` exposed.
- `closing` could be simplified.
-  indentation on the render method could be improved.

Feel free to throw this away if you disagree. Just thought I'd offer this to be more readable.
  • Loading branch information
sportnak authored Aug 25, 2017
1 parent d3dd5e5 commit dd31e17
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions examples/Sample1/share.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ShareExtension from 'react-native-share-extension'

import {
Text,
TextInput,
View,
TouchableOpacity
} from 'react-native'
Expand All @@ -24,7 +23,7 @@ export default class Share extends Component {
}
}

async componentDidMount() {
async componentDidMount = () => {
try {
const { type, value } = await ShareExtension.data()
this.setState({
Expand All @@ -36,30 +35,29 @@ export default class Share extends Component {
}
}

onClose() {
ShareExtension.close()
}
onClose = () => ShareExtension.close()

closing = () => {
this.setState({
isOpen: false
})
}
closing = () => this.setState({ isOpen: false });

render() {
return (
<Modal backdrop={false}
style={{ backgroundColor: 'transparent' }} position="center" isOpen={this.state.isOpen} onClosed={this.onClose}>
<View style={{ alignItems: 'center', justifyContent:'center', flex: 1 }}>
<View style={{ borderColor: 'green', borderWidth: 1, backgroundColor: 'white', height: 200, width: 300 }}>
<TouchableOpacity onPress={this.closing}>
<Text>Close</Text>
<Text>type: { this.state.type }</Text>
<Text>value: { this.state.value }</Text>
</TouchableOpacity>
</View>
<Modal
backdrop={false}
style={{ backgroundColor: 'transparent' }}
position="center"
isOpen={this.state.isOpen}
onClosed={this.onClose}
>
<View style={{ alignItems: 'center', justifyContent:'center', flex: 1 }}>
<View style={{ borderColor: 'green', borderWidth: 1, backgroundColor: 'white', height: 200, width: 300 }}>
<TouchableOpacity onPress={this.closing}>
<Text>Close</Text>
<Text>type: { this.state.type }</Text>
<Text>value: { this.state.value }</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
)
);
}
}

0 comments on commit dd31e17

Please sign in to comment.