Skip to content

Instantly share code, notes, and snippets.

@skiph

skiph/AppFragment.js

Last active May 2, 2018
Embed
What would you like to do?
RNDemo - App getShape fragment
import Approov from './Approov';
class App extends React.Component {
// unchanged code ommitted for brevity...
// get shape
getShape = () => {
Approov.fetch('https://demo-server.approovr.io/shapes', {
method: 'GET',
})
.then((response) => {
if (!response.ok) {
throw new Error('HTTP response status not OK.');
}
return response.text();
})
.then((text) => {
this.setState(previousState => {
return { shape: text, status: '' };
})
})
.catch((error) => {
const message = '' + error.message;
this.setState(previousState => {
return { shape: 'confused', status: message };
})
});
}
// render the app screen
render() {
let pic = {
uri: 'https://approov.io/images/approov_largelogo.png'
};
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={{fontSize: 24}}>Approov Shapes</Text>
</View>
<ShapeView style={styles.content} shape={this.state.shape} status={this.state.status}/>
<View style={styles.footer}>
<View style={styles.buttonBar}>
<Button onPress={this.checkConnection} title="Test Hello" />
<Button onPress={this.getShape} title="Get Shape" />
</View>
</View>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment