Skip to content

Instantly share code, notes, and snippets.

@AllanGraves
AllanGraves / Locations.js
Created January 14, 2021 18:59
code using state to display text in a location component
const Location = ({jsondata, locationID, storyID}) => {
console.log(`Location: LocationID: ${locationID} + StoryID: ${storyID}`);
/* This holds the current location we are displaying */
const [curLocation, setLocation] = useState(locationID);
const [curStory, setStory] = useState(storyID);
var textToDisplay = jsondata[curLocation].text;
textToDisplay = ParserClass.parseText(textToDisplay);
return (
@AllanGraves
AllanGraves / App.js
Created January 7, 2021 20:20
Screen Four
const ScreenFour = ({navigation, route}) => {
useEffect(() => {
console.log('Screen 4 Mount: ');
console.log(navigation.dangerouslyGetState());
console.log(route);
return () => {
console.log('Screen 4 Unmount:');
console.log(navigation.dangerouslyGetState());
};
@AllanGraves
AllanGraves / App.js
Created January 6, 2021 21:09
Simple Tab Navigator
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
const TabScreens = () => {
return (
<Tab.Navigator>
<Tab.Screen name="One" component={ScreenOne} />
<Tab.Screen name="Two" component={ScreenTwo} />
<Tab.Screen name="Three" component={ScreenThree} />
</Tab.Navigator>
@AllanGraves
AllanGraves / App.js
Created January 6, 2021 20:59
Hiding our 'replace' button
const ScreenOne = ({navigation}) => {
useEffect(() => {
console.log('Screen 1 Mount: ');
console.log(navigation.dangerouslyGetState());
return () => {
console.log('Screen 1 Unmount:');
console.log(navigation.dangerouslyGetState());
};
});
@AllanGraves
AllanGraves / App.js
Created January 6, 2021 20:35
Simple drawer navigator
const Drawer = createDrawerNavigator();
const DrawerScreens = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="One" component={ScreenOne} />
<Drawer.Screen name="Two" component={ScreenTwo} />
<Drawer.Screen name="Three" component={ScreenThree} />
</Drawer.Navigator>
);
};
@AllanGraves
AllanGraves / App.js
Created January 5, 2021 21:28
A small React State Hook to simulate the didComponentMount and willComponentUnmount React Life cycle functions
useEffect(() => {
console.log('Screen 1 Mount: ');
console.log(navigation.dangerouslyGetState());
return () => {
console.log('Screen 1 Unmount:');
console.log(navigation.dangerouslyGetState());
};
});
@AllanGraves
AllanGraves / App.js
Created January 5, 2021 19:29
Changing our screens to have the ability to navigate
const ScreenOne = ( {navigation} ) => {
return (
<View>
<Text> Screen One </Text>
<Button
title="Go to Two"
onPress={() => navigation.navigate('Two')}
/>
</View>
);
@AllanGraves
AllanGraves / App.js
Last active January 5, 2021 19:24
Setting up a basic Stack Navigator
import 'react-native-gesture-handler';
import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {SafeAreaView, ScrollView, View, Text, StatusBar} from 'react-native';
const ScreenOne = () => {
return (
<View>
<Text> Screen One </Text>
@AllanGraves
AllanGraves / App.js
Created January 3, 2021 12:39
3 simple screens
const ScreenOne = () => {
return (
<View>
<Text> Screen One </Text>
</View>
);
};
const ScreenTwo = () => {
return (
@AllanGraves
AllanGraves / App.js
Created January 3, 2021 12:19
Initial Setup for a React Native Navigation Container
import 'react-native-gesture-handler';
import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {SafeAreaView, ScrollView, View, Text, StatusBar} from 'react-native';
const App: () => React$Node = () => {
return (
<>