Changing TouchableHighlight style when user clicks - reactjs

Essentially I want a button, where once it's clicked/pressed the style of that button changes.
In particular, the picture I posted is the style that I am trying to achieve.I have a bar with three rows. When the user presses on one of these three rows, the row which is clicked will have a white underline underneath it.
navbar
import React from 'react';
import {
StyleSheet,
Text,
Alert,
Button,
TouchableHighlight,
View,
TextInput,
ScrollView,
TouchableOpacity,
}from 'react-native';
export default class Main extends React.Component {
constructor(props){
super(props)
this.state= { onPress: false};
}
onPress = () => {
Alert.alert("You have pressed button");
}
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerText}> Welcome!</Text>
</View>
<View style= {styles.headerSecond}>
<TouchableHighlight
style= {this.state.onPress? styles.buttonPress : styles.button}
onPress= {this.onPress}
underlayColor='transparent'
>
<Text style= {styles.headerSecondText}>Troops</Text>
</TouchableHighlight>
<TouchableHighlight
style= {styles.button}
onPress= {this.onPress}
underlayColor='transparent'
>
<Text style= {styles.headerSecondText}>Towers</Text>
</TouchableHighlight>
<TouchableHighlight
style= {styles.button}
onPress= {this.onPress}
underlayColor='transparent'
>
<Text style= {styles.headerSecondText}>Bases</Text>
</TouchableHighlight>
</View>
<View style={styles.headerOption}>
</View>
<ScrollView>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
header: {
backgroundColor: '#80bfff',
alignItems: 'center',
justifyContent: 'center',
padding: 36,
},
headerSecond:{
backgroundColor: '#4da6ff',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
},
headerSecondText: {
color: 'white',
fontSize: 18,
padding: 14,
},
button: {
alignItems: 'center',
padding:10,
},
buttonPress:{
alignItems: 'center',
backgroundColor: 'black',
},
headerText:{
color: 'white',
fontSize: 22,
padding: 26,
},
});

Related

How to update screen dimensions in react native

I have been trying to update my screen dimensions in react native so that the component resizes on-screen rotation with no vain. I have created my style in a separate file (Styles.js) and imported the styles in my login page like below:
Styles.js
import {
StyleSheet,
Dimensions
} from "react-native";
import {
scale,
ScaledSheet
} from "react-native-size-matters";
const styles = ScaledSheet.create({
scrollViewContainer: {
backgroundColor: '#E20030',
alignItems: 'center',
height: Dimensions.get('window').height,
padding: '50#s'
},
container2: {
alignItems: 'center',
justifyContent: 'center',
width: Dimensions.get('window').width,
flex: 1,
},
loginRect: {
borderRadius: '30#s',
marginTop: '20#s',
width: Dimensions.get('window').width * 0.8,
backgroundColor: 'white',
alignItems: 'center'
},
SectionStyle: {
flexDirection: 'row',
marginTop: 0,
marginLeft: '35#s',
marginRight: '35#s',
borderWidth: '1#s',
borderRadius: '5#s',
borderColor: '#dadae8',
},
});
Login.js
import React, { } from 'react';
import {
Text, View, TextInput, TouchableOpacity,
KeyboardAvoidingView,
} from 'react-native';
import { mystyles, styles } from './Components/styles';
const LoginScreen = () => {
return (
<View style={mystyles.scrollViewContainer}>
<KeyboardAvoidingView behavior="padding" style={{ flex: 100 }}>
<View style={mystyles.scrollViewContainer}>
<View style={mystyles.loginRect}>
<View style={{ flexDirection: 'row' }}>
<View style={{ flex: 1, marginLeft: 45, marginTop: 20 }}>
<Text style={{ color: 'black' }}>Username</Text>
</View>
</View>
<View style={styles.SectionStyle}>
<TextInput
style={styles.input}
/>
</View>
<View style={{ flexDirection: 'row' }}>
<View style={{ flex: 1, marginLeft: 45, marginTop: 20 }}>
<Text style={{ color: 'black' }}>Password</Text>
</View>
</View>
<View style={styles.SectionStyle}>
<TextInput
style={styles.input}
/>
</View>
<TouchableOpacity>
<Text style={styles.buttonTextStyle}>LOGIN</Text>
</TouchableOpacity>
</View>
</View>
</KeyboardAvoidingView>
</View>
)
}
export default LoginScreen;
So I have tried using Dimensions onchange listener in my Styles.js but I get an error
ERROR Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
I created this function in the Styles.js file
m
function getDimensions() {
const [dimensions, setDimensions] = useState({
window,
screen
});
useEffect(() => {
const subscription = Dimensions.addEventListener(
"change",
({
window,
screen
}) => {
setDimensions({
window,
screen
});
console.log(dimensions.window.height + " +++ " + dimensions.screen)
}
);
// return () => subscription?.remove();
});
return dimensions.window;
}
Is there any way I can update the component sizes once the screen has been rotated?
This is working for me to detect rotation or changes in the size of the screen (split mode in tablets for example) without eventListeners.
import { Dimensions } from "react-native";
...
useEffect(() => {
...
}, [Dimensions.get("screen").height, Dimensions.get("screen").width]);
Hope this help to anybody

AsyncStorage not storing data and subsequently does not retrieve data

I am using expo and react-native
I am trying to use AsyncStorage to save 3 values in persistent storage
so I can get it from anywhere in the app,
but asyncstorage is not saving or retrieving,
I have rewritten the code several times and several diffrent ways and have tried a few tutorials, nothing works,
so here is the code for the page where i save the data (Login.js)
import React, { useState} from 'react'
import { View, Text,TextInput ,Button,SafeAreaView,Image,} from 'react-native'
import { ProgressDialog,Dialog } from 'react-native-simple-dialogs';
import AsyncStorage from '#react-native-community/async-storage';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
function Login ({navigation}){
const[alerted,isalerted]=useState(false)
const[authError,setAuthError]=useState(false)
const[accInactive,isAccInactive]=useState(false)
const[loginFail,didLoginFail]=useState(false)
const[login,didLogin]=useState(false)
const[email,setemail]=useState(email)
const[ClientID,setClientID]=useState(ClientID)
const[Password,setPassword]=useState(Password)
Here I am Trying to set the items for Asyncstorage
function LoginButton () {
AsyncStorage.setItem("MyEmail",email)
AsyncStorage.setItem("MyPassword",Password)
AsyncStorage.setItem("MyClientID",ClientID)
fetch('https://www.SITE.co.za/app-login.asp?ClientID='+ClientID+'&Username='+email+'&Pwd='+Password)
.then((response) => response.json())
.then((responseJson) => {
//Successful response from the API Call
if (JSON.stringify(responseJson).includes("Login Success")){
{isalerted(true),didLogin(false),isLoggedIn('Yes')}
}
else if (JSON.stringify(responseJson).includes("No Authentication Details Received"))
{
{setAuthError(true)}
}
else if (JSON.stringify(responseJson).includes("Account Not Active"))
{
{isAccInactive(true)}
}
else if (JSON.stringify(responseJson).includes("Login Details Incorrect"))
{
{didLoginFail(true)}
}
})
.catch((error) => {
console.error(error);
});
}
function navButton(){
navigation.navigate('Dashboard')
isalerted(false)
}
return (
<KeyboardAwareScrollView keyboardShouldPersistTaps='handled'>
<SafeAreaView>
<ProgressDialog
visible={didLogin}
activityIndicatorColor="#4994CF"
activityIndicatorSize="large"
animationType="slide"
title="Logging in"
message="Please, wait..."
/>
<Dialog
visible={alerted}
onTouchOutside={''} >
<View>
<Text style={{color:'green',fontSize:20, marginBottom:10 ,textAlign:"center"}}>Login Success</Text>
<Button
title="Continue To Dashboard"
onPress={navButton}
/>
</View>
</Dialog>
<Dialog
visible={authError}
onTouchOutside={''} >
<View>
<Text style={{color:'red',fontSize:20, marginBottom:10 ,textAlign:"center"}}>No Authentication Details Received</Text>
<Button
title="OK"
onPress={ ()=>setAuthError(false)}
/>
</View>
</Dialog>
<Dialog
visible={accInactive}
onTouchOutside={''} >
<View>
<Text style={{color:'red',fontSize:20, marginBottom:10 ,textAlign:"center"}}>Account Not Active</Text>
<Button
title="OK"
onPress={ () =>isAccInactive(false)}
/>
</View>
</Dialog>
<Dialog
visible={loginFail}
onTouchOutside={''} >
<View>
<Text style={{color:'red',fontSize:20, marginBottom:10 ,textAlign:"center"}}>Login Details Incorrect</Text>
<Button
title="OK"
onPress={()=> didLoginFail(false)}
/>
</View>
</Dialog>
<View style={{flexDirection:"row"}}>
<Image source={{uri: 'https://www.SITEe.co.za/images/smartpractice-logo-02.png'}}
style={{marginTop:35,paddingTop:10
, height: 80,width:360,flexWrap:'wrap',resizeMode:"contain" }} />
<Text style={{textAlign:'center',color:"#4994CF", marginTop:35}}>Beta</Text>
</View>
<View style={{width:'95%',alignContent:'center',marginLeft:10}}>
<Text style={{fontSize:20,color:'grey'}}>Welcome to the SmartPractice Beta App,
Please Login below with your SmartPractice login Details
</Text>
</View>
<View style={{marginTop:10,alignItems:"center"}}>
<View style={styles.Label}>
<Text style={styles.LabelText}>Email</Text>
</View>
<TextInput onChangeText={(text)=>setemail(text)} autoCompleteType='email' placeholder="Email" style={{width:'95%',height:40,backgroundColor:'#d8d8d8',marginBottom:3, paddingHorizontal: 10,marginTop:5}}/>
<View style={styles.Label}>
<Text style={styles.LabelText}>Password</Text>
</View>
<TextInput onChangeText={(text)=>setPassword(text)} autoCompleteType="password" secureTextEntry={true} placeholder="Password" style={{width:'95%',height:40,backgroundColor:'#d8d8d8',marginBottom:3, paddingHorizontal: 10,marginTop:5}}/>
<View style={styles.Label}>
<Text style={styles.LabelText}>ClientID</Text>
</View>
<TextInput onChangeText={(text)=>setClientID(text)} keyboardType="numeric" placeholder="ClientID" style={{width:'95%',height:40,backgroundColor:'#d8d8d8',marginBottom:3, paddingHorizontal: 10,marginTop:5}}/>
<View style={{marginTop:5,width:'95%'}}>
<View style={{width:'95%',alignContent:'center',marginLeft:10,marginBottom:10}}>
<Text style={{fontSize:15,color:'grey'}}>ClientID : Log into Smartpractice on the internet and use the 4 digit number at the end of your URL (internet Address) of your login screen
</Text>
</View>
<Button
title="Save"
onPress={LoginButton}
/>
</View>
</View>
</SafeAreaView>
</KeyboardAwareScrollView>
);
}
const styles = {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop:5
},
Label: {
backgroundColor:'#A6A5A4',
color:"white",
textAlign: "center",
marginTop:2,
fontSize: 15,
width:'100%',
},
alertmessage:{
color:'green'
},
LabelText: {
backgroundColor:'#A6A5A4',
color:"white",
textAlign: "center",
fontSize: 20,
},
};
export default Login;
The here is where I am trying to retrieve some of the data (Dashboard.js)
import React, {Component } from 'react'
import { View, Text,Image,TouchableOpacity,StyleSheet,SafeAreaView,} from 'react-native'
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
import AsyncStorage from '#react-native-community/async-storage';
function Dashboard ({navigation}){
let MyClientID = AsyncStorage.getItem("MyClientID")
console.log(global.mail)
return (
<KeyboardAwareScrollView keyboardShouldPersistTaps='handled'>
<SafeAreaView style={styles.container}>
<View style={{flexDirection:"row"}}>
<Image source={{uri: 'https://www.site.co.za/images/smartpractice-logo-02.png'}}
style={{marginTop:5,paddingTop:10
, height: 80,width:360,flexWrap:'wrap',resizeMode:"contain" }} />
<Text style={{textAlign:'center',color:"#4994CF", marginTop:35}}>Beta</Text>
</View>
<Image source={{uri: 'https://www.site.co.za/images/logos/'+MyClientID+'/main-dashboard-logo.png'}}
style={{marginTop:5,paddingTop:10
, height: 70,width:'100%',flexWrap:'wrap',resizeMode:"contain",marginLeft:5 }} />
<View style={{justifyContent:"center", marginTop:6}}>
<Text style={styles.DateLabel}>Description</Text>
</View>
<TouchableOpacity style={styles.ImageButton}
onPress={() => navigation.navigate('Incidental Time')}
>
<Image style={{flexWrap:'wrap',resizeMode:"contain",maxHeight:120,maxWidth:120 }} tintColor='#4994CF' source={require('../../icons/time_log.png')} />
<Text style={styles.TextStyle}>Time Log</Text>
</TouchableOpacity>
</SafeAreaView>
</KeyboardAwareScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textInput: {
backgroundColor:'#A6A5A4',
color:"white",
textAlign: "center",
marginTop:5,
fontSize: 20,
marginBottom:5
,marginLeft:1
},
DateLabel: {
backgroundColor:'#A6A5A4',
color:"white",
textAlign: "center",
marginTop:2,
fontSize: 20,
paddingLeft:140,
paddingRight:140,
width:'100%',
marginBottom:10
},
ImageButton: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
TextStyle:{
color:"grey"
}
});
export default Dashboard;
I have tried setting the items in a useeffect wrapping the values in the setitems in STRING()
tried making functions and const with async attached and the await before the set/getitem
I have check SO for hours and none of the answers or questions have helped me with this
I seriously dont know what I am doing wrong
I followed the asynstorage docs and even copying the code from the docs does not work
I dont get errors, Its been 2 days of struggling with something as simple as local storage
Please help
Both getItem and setItem of AsyncStorage are Promise so you need to use await or callback.
For setItem, current usage is okay but for getItem, it is essential.
You also need to use getItem in useEffect and make MyClientID as a state.
Try the following code instead of your Dashborad.js:
import React, {Component} from 'react';
import {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
SafeAreaView,
} from 'react-native';
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
import AsyncStorage from '#react-native-community/async-storage';
function Dashboard({navigation}) {
const [MyClientID, setMyClientID] = useState('');
useEffect(() => {
AsyncStorage.getItem('MyClientID').then((myClientID) => {
setMyClientID(myClientID);
});
}, []);
console.log(global.mail);
return (
<KeyboardAwareScrollView keyboardShouldPersistTaps="handled">
<SafeAreaView style={styles.container}>
<View style={{flexDirection: 'row'}}>
<Image
source={{
uri: 'https://www.site.co.za/images/smartpractice-logo-02.png',
}}
style={{
marginTop: 5,
paddingTop: 10,
height: 80,
width: 360,
flexWrap: 'wrap',
resizeMode: 'contain',
}}
/>
<Text style={{textAlign: 'center', color: '#4994CF', marginTop: 35}}>
Beta
</Text>
</View>
<Image
source={{
uri:
'https://www.site.co.za/images/logos/' +
MyClientID +
'/main-dashboard-logo.png',
}}
style={{
marginTop: 5,
paddingTop: 10,
height: 70,
width: '100%',
flexWrap: 'wrap',
resizeMode: 'contain',
marginLeft: 5,
}}
/>
<View style={{justifyContent: 'center', marginTop: 6}}>
<Text style={styles.DateLabel}>Description</Text>
</View>
<TouchableOpacity
style={styles.ImageButton}
onPress={() => navigation.navigate('Incidental Time')}>
<Image
style={{
flexWrap: 'wrap',
resizeMode: 'contain',
maxHeight: 120,
maxWidth: 120,
}}
tintColor="#4994CF"
source={require('../../icons/time_log.png')}
/>
<Text style={styles.TextStyle}>Time Log</Text>
</TouchableOpacity>
</SafeAreaView>
</KeyboardAwareScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textInput: {
backgroundColor: '#A6A5A4',
color: 'white',
textAlign: 'center',
marginTop: 5,
fontSize: 20,
marginBottom: 5,
marginLeft: 1,
},
DateLabel: {
backgroundColor: '#A6A5A4',
color: 'white',
textAlign: 'center',
marginTop: 2,
fontSize: 20,
paddingLeft: 140,
paddingRight: 140,
width: '100%',
marginBottom: 10,
},
ImageButton: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
TextStyle: {
color: 'grey',
},
});
export default Dashboard;
Not related to your Query but to be honest, based from my experience, Expo is the last thing you wanna use in your project. Especially if you'll be introducing Native dependencies later.
I know you can use ExpoKit then, but still... Don't use Expo
Instead of KeyboardAwareScrollView you can use Content from NativeBase.
For your query, all methods in AsyncStorage are Asynchronous. So remember to use await to get your values
async function fetchLocal(){
const persisted = await AsyncStorage.getItem("persisted");
if(persisted){
console.log(JSON.parse(persisted)); // Oh! the value for these persisted keys needs to be a string, so make sure to String()|.toString()|JSON.stringify objects you wanna serialize.
}
}

How to fix cornerRadius in text element in react native

I am new to react native and am struggling to round the corners to text elements, as you can see the corners are still sticking out of the rounded border, and the same happens when I wrap the text in a view element, I don't know how to fix this. Here is the code:
import React from 'react';
import { StyleSheet, Text, View, Button, Alert, Touchable, TouchableHighlight} from 'react-native';
import { render } from 'react-dom';
export default class App extends React.Component {
myButtonPressed(){
Alert.alert("Logout");
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight
onPress={this.myButtonPressed}
>
<Text style={styles.text}> Login </Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 30,
backgroundColor: "#BB2CD9",
paddingVertical: 10,
paddingHorizontal: 40,
color: "#FFFFFF",
borderRadius: 10,
borderWidth: 2,
borderColor: "#FFFFFF"
}
});
What you can do is wrap the text inside view component and pass all neccessary styling to the view.
export default class App extends React.Component {
myButtonPressed(){
Alert.alert("Logout");
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight
onPress={this.myButtonPressed}
>
<View style={styles.btnContainer}>
<Text style={styles.text}> Login </Text>
</View>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
btnContainer: {
backgroundColor: "#BB2CD9",
paddingVertical: 10,
paddingHorizontal: 40,
borderRadius: 10,
borderWidth: 2,
borderColor: "#FFFFFF"
},
text: {
fontSize: 30,
color: "#FFFFFF",
}
});
You can use TouchableOpacity for better experience. You don't need to define border n all with TouchableOpacity.
Try this - Live Demo
export default class App extends React.Component {
myButtonPressed(){
Alert.alert("Logout");
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity
onPress={this.myButtonPressed}
style={styles.hLight}
>
<Text style={styles.text}> Login </Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
hLight: {
fontSize: 30,
backgroundColor: "#BB2CD9",
paddingVertical: 10,
paddingHorizontal: 40,
borderRadius: 10,
borderWidth: 2,
borderColor: "#FFFFFF"
},
text: {
fontSize:20,
color:'white'
}
});
Using TouchableHighlight - Live
export default class App extends React.Component {
myButtonPressed(){
Alert.alert("Logout");
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight
onPress={this.myButtonPressed}
style={styles.hLight}
>
<Text style={styles.text}> Login </Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
hLight: {
fontSize: 30,
backgroundColor: "#BB2CD9",
paddingVertical: 10,
paddingHorizontal: 40,
borderRadius: 10,
borderWidth: 2,
borderColor: "#FFFFFF"
},
text: {
fontSize:20,
color:'white'
}
});

React native: change button size in center screen

I am new to React Native currently learning about the technology.
I start create a card layout with buttons inside it.
This is my layout :
<KeyboardAvoidingView
behavior='padding'
keyboardVerticalOffset={50}
style={styles.screen}>
<LinearGradient
colors={['#ffedff', '#ffe3ff']}
style={styles.gradient}>
<Card style={styles.card}>
<ScrollView>
<View style={styles.buttonContainer}>
<Button
color={Colors.primary}
title='ورود'
onPress={() => { }} />
</View>
</ScrollView>
</Card>
</LinearGradient>
</KeyboardAvoidingView>
and this is my stylesheet :
const styles = StyleSheet.create({
screen: {
flex: 1
},
gradient: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
card: {
width: '90%',
height: '80%',
padding: 20
},
buttonContainer: {
alignItems: 'center',
marginVertical: 30,
},
});
and result is:
I want to make button bigger so i added width to buttonContainer but button changed position to left of screen and its size does not change.
buttonContainer: {
width: '40%',
alignItems: 'center',
marginVertical: 30,
},
How could i change button width when it is in the center of screen?
So basically alignSelf:'center' was the problem. Removing that worked. Check the expo link below and the code :
import React from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
KeyboardAvoidingView,
ScrollView,
Button
} from 'react-native';
import { LinearGradient } from 'expo-linear-gradient'
import Card from './Card';
export default AuthScreen = () => {
return (
<KeyboardAvoidingView
behavior='padding'
keyboardVerticalOffset={50}
style={styles.screen}>
<LinearGradient
colors={['#ffedff', '#ffe3ff']}
style={styles.gradient}>
<Card style={styles.card}>
<ScrollView>
{/* <View style={styles.wcContainer}>
<Text style={styles.headerText}>خوش آمدید</Text>
</View> */}
{/* <View style={styles.container}>
<Text style={styles.text}>نام کاربری</Text>
<TextInput style={styles.input} />
<Text style={styles.text}>رمز عبور</Text>
<TextInput style={styles.input} />
</View> */}
<View style={styles.buttonContainer}>
<Button
color= 'red'
title='ورود'
style={{marginHorizontal:200}}
onPress={() => { }} />
</View>
</ScrollView>
</Card>
</LinearGradient>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1
},
gradient: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
card: {
width: '90%',
height: '80%',
padding: 20
},
buttonContainer: {
// marginHorizontal:200,
width:'100%',
// alignItems: 'center',
// marginVertical: 30,
justifyContent:'center'
},
});
expo link : expo link
hope it helps. feel free for doubts
I fixed this problem with :
buttonContainer: {
width: '40%',
alignSelf: 'center',
marginVertical: 30,
}
Now this is my layout:

Unexpected token, expected "}" at my countText case

Please bear with me as I am new to all of this and this is my first posted question! I am trying to set up a simple "welcome screen" with a signup button , and am just learning the ios/App development process/ react-native and javascript. Can anyone explain exactly why there is an error at the line 68? I got this error previously and thought it may be because I was "calling"the styles outside of the class, but I believe that is only an issue if this were a function and not a class?
Error Reads: Failed to load bundle(http://localhost:8081/index.bundle?
platform=ios&dev=true&minify=false) with error:(SyntaxError: /Users/name/appname/App.js: Unexpected token, expected “}” (68:13)
type Props = {};
export default class App extends Component<Props> {
render() {
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 10
},
button: {
alignItems: "center",
backgroundColor: "blue",
width: 100,
padding: 10
},
countText: {
padding: 20,
color: "#FF00FF"
}
});
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to P2P Blockchain!</Text>
<Text style={styles.instructions}>To get started, click below!</Text>
<View style={styles.container}>
<TouchableHighlight style={styles.button} onPress={this.onPress}>
<Text> Sign Up Here! </Text>
</TouchableHighlight>
<View style={[styles.countContainer]}>
<Text style={[styles.countText]}>
{this.state.count !== 0 ? this.state.count : null}
</Text>
</View>
</View>
</View>
);
}
}
import React, { Component } from 'react';
import { View, StyleSheet, TouchableHighlight, Text } from 'react-native';
type Props = {};
class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
count: 10,
};
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to P2P Blockchain!</Text>
<Text style={styles.instructions}>To get started, click below!</Text>
<View style={styles.container}>
<TouchableHighlight style={styles.button} onPress={this.onPress}>
<Text> Sign Up Here! </Text>
</TouchableHighlight>
<View style={styles.countContainer}>
<Text style={styles.countText}>
{this.state.count !== 0 ? this.state.count : null}
</Text>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 10
},
button: {
alignItems: "center",
backgroundColor: "blue",
width: 100,
padding: 10
},
countText: {
padding: 20,
color: "#FF00FF"
}
});
export default App;

Resources