Skip to content

Instantly share code, notes, and snippets.

@mjonesjr90
Created September 11, 2018 18:25
Show Gist options
  • Save mjonesjr90/8f7782e44c12262ceb62c9b10499fcfc to your computer and use it in GitHub Desktop.
Save mjonesjr90/8f7782e44c12262ceb62c9b10499fcfc to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Image, Button} from 'react-native';
import ToastModule from 'react-native-toast-library';
type Props = {};
var pic = {uri: 'https://developer.android.com/images/brand/Android_Robot_200.png'};
var osName = 'Android';
class OS extends Component {
render() {
return (
<Text style={{fontSize: 30}}>{this.props.name}</Text>
);
}
}
export default class App extends Component<Props> {
constructor(props) {
super(props);
//setup state
this.state = {
displayOS: 'android'
};
}
renderPage = () => {
if(osName === "Android") {
pic = {uri: 'https://www.apple.com/ios/images/og.png?201805211344'}
osName = 'iOS';
console.log('changing to ios');
ToastModule.show('Android');
return this.setState({displayOS: 'ios'});
}
else{
pic = {uri: 'https://developer.android.com/images/brand/Android_Robot_200.png'};
osName = 'Android';
console.log('changing to android');
ToastModule.show('iOS');
return this.setState({displayOS: 'android'});
}
}
render() {
return (
<View style={styles.container}>
<Image source={pic} style={{width:200, height:237}}/>
<OS name={osName}/>
<Button
onPress={this.renderPage}
title="Switch"
color="#000000"
accessibilityLabel="Switch"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment