Skip to content

Commit

Permalink
feat: add navigation in example
Browse files Browse the repository at this point in the history
  • Loading branch information
dohooo committed Dec 11, 2021
1 parent 5287a09 commit 1687f1d
Show file tree
Hide file tree
Showing 11 changed files with 668 additions and 52 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
useTabs: false,
},
],
'react-native/no-inline-styles': 0,
},
};
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerRootComponent } from 'expo';

import App from './src/App';
import App from './src/index';

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in the Expo client or in a native build,
Expand Down
6 changes: 6 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
"test": "jest"
},
"dependencies": {
"@react-navigation/core": "^6.1.0",
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"babel-loader": "^8.2.3",
"expo": "^41.0.0",
"expo-splash-screen": "~0.10.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "0.63.4",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.0.0",
"react-native-ui-lib": "^6.5.4",
"react-native-unimodules": "~0.13.3",
"react-native-web": "~0.13.12"
},
Expand Down
80 changes: 43 additions & 37 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/* eslint-disable react-native/no-inline-styles */
import * as React from 'react';
import {
Button,
Dimensions,
Image,
ImageSourcePropType,
View,
} from 'react-native';
import { Button, Dimensions, Text, View } from 'react-native';
import Carousel from '../../src/index';
import type { ICarouselInstance } from '../../src/types';
import Animated, {
Expand All @@ -19,10 +12,19 @@ import Animated, {
const window = Dimensions.get('window');
const PAGE_WIDTH = window.width;

const data: ImageSourcePropType[] = [
require('../assets/carousel-0.jpg'),
require('../assets/carousel-1.jpg'),
require('../assets/carousel-2.jpg'),
interface DataItem {
text: string;
backgroundColor: string;
}

const data: DataItem[] = [
{ text: 'Walter, Wintheiser and Von', backgroundColor: '#ffbb96' },
{ text: 'Herman, Dicki and Wintheiser', backgroundColor: '#ff9c6e' },
{ text: 'Wiza, Borer and Muller', backgroundColor: '#ff7a45' },
{ text: 'Kulas Group', backgroundColor: '#fa541c' },
{ text: 'Rowe, Gerhold and Corkery', backgroundColor: '#d4380d' },
{ text: 'Lang - Doyle', backgroundColor: '#ad2102' },
{ text: "Anderson, Leuschke and O'Keefe", backgroundColor: '#871400' },
];

export default function App() {
Expand All @@ -34,7 +36,7 @@ export default function App() {
style={{
flex: 1,
alignItems: 'center',
backgroundColor: 'black',
backgroundColor: '#f1f1f1',
paddingTop: 100,
}}
>
Expand All @@ -45,18 +47,20 @@ export default function App() {
width={PAGE_WIDTH}
parallaxScrollingScale={0.8}
data={data}
renderItem={(source, index) => {
return (
<Image
key={index}
source={source}
style={{
width: '100%',
height: '100%',
}}
/>
);
}}
renderItem={({ backgroundColor, text }) => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor,
}}
>
<Text style={{ color: 'white', fontSize: 30 }}>
{text}
</Text>
</View>
)}
/>
</View>
<View
Expand Down Expand Up @@ -93,18 +97,20 @@ export default function App() {
width={window.width}
parallaxScrollingScale={0.8}
data={data}
renderItem={(source, i) => {
return (
<Image
key={i}
source={source}
style={{
width: '100%',
height: '100%',
}}
/>
);
}}
renderItem={({ backgroundColor, text }) => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor,
}}
>
<Text style={{ color: 'white', fontSize: 20 }}>
{text}
</Text>
</View>
)}
/>
{!!progressValue && (
<View
Expand Down
40 changes: 40 additions & 0 deletions example/src/home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';
import { View, Text } from 'react-native';
import { useNavigation, NavigationProp } from '@react-navigation/native';
import { RootStackParamList } from '../index';
import { Colors, ListItem } from 'react-native-ui-lib';

const LayoutsPage: Array<Record<'name', keyof RootStackParamList>> = [
{
name: 'Normal',
},
{
name: 'Parallax',
},
];

const Index = () => {
const navigation = useNavigation<NavigationProp<RootStackParamList>>();
return (
<View style={{ flex: 1 }}>
{LayoutsPage.map(({ name }, index) => {
return (
<ListItem
key={index}
onPress={() => navigation.navigate(name)}
style={{
// justifyContent: 'center',
alignItems: 'center',
borderColor: Colors.grey60,
borderBottomWidth: 1,
}}
>
<Text>{name}</Text>
</ListItem>
);
})}
</View>
);
};

export default Index;
29 changes: 29 additions & 0 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

import Home from './home';
import NormalComponent from './normal';
import ParallaxComponent from './parallax';

const Stack = createNativeStackNavigator<RootStackParamList>();

export type RootStackParamList = {
Home: undefined;
Normal: undefined;
Parallax: undefined;
};

function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Normal" component={NormalComponent} />
<Stack.Screen name="Parallax" component={ParallaxComponent} />
</Stack.Navigator>
</NavigationContainer>
);
}

export default App;
83 changes: 83 additions & 0 deletions example/src/normal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import * as React from 'react';
import { Button, Dimensions, Text, View } from 'react-native';
import Carousel from '../../../src/index';
import type { ICarouselInstance } from '../../../src/types';

const window = Dimensions.get('window');
const PAGE_WIDTH = window.width;

interface DataItem {
text: string;
backgroundColor: string;
}

const data: DataItem[] = [
{ text: 'Walter, Wintheiser and Von', backgroundColor: '#ffbb96' },
{ text: 'Herman, Dicki and Wintheiser', backgroundColor: '#ff9c6e' },
{ text: 'Wiza, Borer and Muller', backgroundColor: '#ff7a45' },
{ text: 'Kulas Group', backgroundColor: '#fa541c' },
{ text: 'Rowe, Gerhold and Corkery', backgroundColor: '#d4380d' },
{ text: 'Lang - Doyle', backgroundColor: '#ad2102' },
{ text: "Anderson, Leuschke and O'Keefe", backgroundColor: '#871400' },
];

function Index() {
const r = React.useRef<ICarouselInstance | null>(null);

return (
<View
style={{
flex: 1,
alignItems: 'center',
backgroundColor: '#f1f1f1',
paddingTop: 100,
}}
>
<View style={{ width: PAGE_WIDTH, height: 240 }}>
<Carousel
defaultIndex={0}
ref={r}
width={PAGE_WIDTH}
parallaxScrollingScale={0.8}
data={data}
renderItem={({ backgroundColor, text }) => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor,
}}
>
<Text style={{ color: 'white', fontSize: 30 }}>
{text}
</Text>
</View>
)}
/>
</View>
<View
style={{
marginTop: 24,
flexDirection: 'row',
justifyContent: 'space-evenly',
}}
>
<Button
title="Prev"
onPress={() => {
r.current?.prev();
}}
/>
<Button
title="Next"
onPress={() => {
r.current?.next();
}}
/>
</View>
</View>
);
}

export default Index;
Loading

0 comments on commit 1687f1d

Please sign in to comment.