Skip to content

Instantly share code, notes, and snippets.

@skiph
Last active May 2, 2018 19:51
Show Gist options
  • Save skiph/6df402a284b908554510086f6b928b23 to your computer and use it in GitHub Desktop.
Save skiph/6df402a284b908554510086f6b928b23 to your computer and use it in GitHub Desktop.
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