Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
feat: add theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Sep 4, 2019
1 parent 891b502 commit 9883cd8
Show file tree
Hide file tree
Showing 6 changed files with 2,076 additions and 2,390 deletions.
123 changes: 98 additions & 25 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import * as React from 'react';
import { registerRootComponent } from 'expo';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import { createAppContainer } from '@react-navigation/native';
import { View, TouchableOpacity, StyleSheet } from 'react-native';
import {
Assets as StackAssets,
createStackNavigator,
} from 'react-navigation-stack';
import { Themed, createAppContainer } from '@react-navigation/native';
import { ThemeColors, useTheme } from '@react-navigation/core';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { Asset } from 'expo-asset';

import BottomTabs from './src/BottomTabs';
import MaterialTopTabs from './src/MaterialTopTabs';

class Home extends React.Component {
render() {
return (
<View>
<TouchableOpacity
style={styles.item}
onPress={() => this.props.navigation.push('BottomTabs')}
>
<Text>Bottom tabs</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.item}
onPress={() => this.props.navigation.push('MaterialTopTabs')}
>
<Text>Material top tabs</Text>
</TouchableOpacity>
</View>
);
}
}
// Load the back button etc
Asset.loadAsync(StackAssets);

const Home = props => {
let theme = useTheme();

return (
<View>
<TouchableOpacity
activeOpacity={0.8}
style={theme === 'dark' ? styles.itemDark : styles.itemLight}
onPress={() => props.navigation.push('BottomTabs')}
>
<Themed.Text>Bottom tabs</Themed.Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={0.8}
style={theme === 'dark' ? styles.itemDark : styles.itemLight}
onPress={() => props.navigation.push('MaterialTopTabs')}
>
<Themed.Text>Material top tabs</Themed.Text>
</TouchableOpacity>
<Themed.StatusBar />
</View>
);
};

const List = createStackNavigator({
Home: {
Expand All @@ -42,15 +55,75 @@ const List = createStackNavigator({
},
});

const App = createAppContainer(List);
const Navigation = createAppContainer(List);

const App = () => {
let [theme, setTheme] = React.useState('light');

return (
<View style={styles.container}>
<Navigation theme={theme} />
<View style={styles.buttonContainer}>
<TouchableOpacity
style={[
styles.button,
{
backgroundColor: ThemeColors[theme].bodyContent,
borderColor: ThemeColors[theme].bodyBorder,
shadowColor: ThemeColors[theme].label,
},
]}
onPress={() => {
setTheme(theme === 'light' ? 'dark' : 'light');
}}
>
<MaterialCommunityIcons
name="theme-light-dark"
size={30}
color={ThemeColors[theme].label}
/>
</TouchableOpacity>
</View>
</View>
);
};

const styles = {
item: {
container: {
flex: 1,
},
buttonContainer: {
position: 'absolute',
bottom: 60,
right: 20,
},
button: {
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.4,
shadowRadius: 2,
borderRadius: 25,
width: 50,
height: 50,
alignItems: 'center',
justifyContent: 'center',
elevation: 5,
borderWidth: 1,
},
itemLight: {
padding: 16,
backgroundColor: '#fff',
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#eee',
},
itemDark: {
padding: 16,
backgroundColor: ThemeColors.dark.bodyContent,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: ThemeColors.dark.bodyBorder,
},
};

registerRootComponent(App);
4 changes: 2 additions & 2 deletions example/app.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"expo": {
"name": "React Navigation Tabs Example",
"description": "Demonstrates the various capabilities of react-navigation-tabs: https://github.com/react-navigation/tabs",
"description": "Demonstrates the various capabilities of react-navigation-tabs: https://github.com/react-navigation/react-navigation-tabs",
"slug": "react-navigation-tabs-demos",
"sdkVersion": "32.0.0",
"sdkVersion": "33.0.0",
"version": "1.0.0",
"primaryColor": "#2196f3",
"packagerOpts": {
Expand Down
27 changes: 14 additions & 13 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
},
"main": "App.js",
"dependencies": {
"@expo/vector-icons": "^10.0.1",
"@react-navigation/core": "^3.4.0",
"@react-navigation/native": "^3.3.0",
"expo": "32.0.6",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"@expo/vector-icons": "^10.0.0",
"@react-navigation/core": "3.5.0-alpha.7",
"@react-navigation/native": "^3.6.0-alpha.1",
"expo": "^33.0.7",
"expo-asset": "^6.0.0",
"expo-constants": "~5.0.1",
"react": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"react-native-safe-area-view": "^0.13.1",
"react-native-screens": "^1.0.0-alpha.22",
"react-native-tab-view": "^2.0.3",
"react-navigation": "^3.6.0"
"react-native-screens": "1.0.0-alpha.22",
"react-native-tab-view": "^1.2.0",
"react-navigation-stack": "1.4.0-alpha.0"
},
"devDependencies": {
"babel-plugin-module-resolver": "^3.2.0",
"babel-preset-expo": "^5.1.1",
"babel-preset-expo": "^5.0.0",
"glob-to-regexp": "^0.4.0"
},
"resolutions": {
"**/@expo/vector-icons": "10.0.1",
"**/@react-navigation/core": "3.4.0",
"**/hoist-non-react-statics": "2.5.0",
"**/react-native-tab-view": "2.0.3"
"**/react-native-tab-view": "1.2.0",
"**/prop-types": "15.6.1"
}
}
78 changes: 78 additions & 0 deletions example/src/Shared/PhotoGrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import * as React from 'react';
import { View, Image, ScrollView, Dimensions, StyleSheet } from 'react-native';
import { withNavigation } from '@react-navigation/core';

@withNavigation
class NavigationAwareScrollView extends React.Component {
componentDidMount() {
this.props.navigation.addListener('willFocus', () => {
this._isFocused = true;
});

this.props.navigation.addListener('willBlur', () => {
this._isFocused = false;
});

this.props.navigation.addListener('refocus', () => {
if (this._isFocused) {
this._component.scrollTo({ x: 0, y: 0 });
}
});
}

setNativeProps(props) {
this._component.setNativeProps(props);
}

_setComponentRef(c) {
this._component = c;
}

getNode() {
return this._component;
}

render() {
return (
<ScrollView
{...this.props}
ref={view => {
this._component = view;
}}
/>
);
}
}

export default function PhotoGrid({ id }) {
const PHOTOS = Array.from({ length: 24 }).map(
(_, i) => `https://unsplash.it/300/300/?random&__id=${id}${i}`
);

return (
<NavigationAwareScrollView contentContainerStyle={styles.content}>
{PHOTOS.map(uri => (
<View key={uri} style={styles.item}>
<Image source={{ uri }} style={styles.photo} />
</View>
))}
</NavigationAwareScrollView>
);
}

const styles = StyleSheet.create({
content: {
flexDirection: 'row',
flexWrap: 'wrap',
padding: 4,
},
item: {
height: Dimensions.get('window').width / 2,
width: '50%',
padding: 4,
},
photo: {
flex: 1,
resizeMode: 'cover',
},
});
Loading

0 comments on commit 9883cd8

Please sign in to comment.