Skip to content

Instantly share code, notes, and snippets.

@KurzGedanke
Created July 3, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KurzGedanke/38484826b8da31d16afebd441b9971aa to your computer and use it in GitHub Desktop.
Save KurzGedanke/38484826b8da31d16afebd441b9971aa to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {SafeAreaView, Text, TextInput, View, StatusBar, Keyboard, Button} from 'react-native';
import styles from './src/styles';
import ConvertIP from './src/component/ConvertIPs'
export default class App extends Component {
constructor(props){
super(props);
this.state = {
hexIP: '',
// initialise state for the view changing
view: ['calc', 'about'],
activeView: 'calc'
};
this.disKeyboard = this.disKeyboard.bind(this);
// binding the changeView method
this.changeView = this.changeView.bind(this);
}
disKeyboard(){
Keyboard.dismiss();
}
changeView(){
// the changeView method to set the state based on the button press
console.log('CHange view!')
if (this.state.activeView == 'calc'){
this.setState = {
activeView: 'about'
}
} else {
this.setState = {
activeView: 'calc'
}
}
}
render() {
return (
<SafeAreaView style={{flex: 1, backgroundColor: '#F5FCFF'}}>
<StatusBar backgroundColor="blue" barStyle="dark-content" />
// conditional rendering if
{this.state.activeView == 'calc' &&
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to Decimal IP!</Text>
<Text>Enter a hexa decimal ip to convert it to a decimal ip</Text>
<TextInput
style={styles.input}
placeholder="Input HEX IP e.g 7F000001"
onChangeText={(hexIP) => this.setState({hexIP})}
/>
<ConvertIP decIP={this.state.hexIP} />
<Button
onPress={this.disKeyboard}
title='Dismiss keyboard'
/>
</View>
}
// conditional rendering for about
{this.state.activeView == 'about' && <Text>About</Text>}
// button which calls the changeView method
<Button
onPress={this.changeView}
title='About'
/>
</SafeAreaView>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment