-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds carousel example to example to Apps (#263)
* fix GestureHandlerRootView issue on Android * Add fox assets * fix react-native-gesture-handler issue on ios * fix linting * Add Carousel shared example * Add Carousel to expo example home screen * update font size * Add Carousel to the expo app * Add Carousel example to the bare app * update carousel example
- Loading branch information
Showing
13 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import 'react-native-gesture-handler'; | ||
|
||
import {AppRegistry} from 'react-native'; | ||
import { AppRegistry } from 'react-native'; | ||
|
||
import { name as appName } from './app.json'; | ||
import App from './src/App'; | ||
import {name as appName} from './app.json'; | ||
|
||
AppRegistry.registerComponent(appName, () => App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import 'react-native-gesture-handler'; | ||
|
||
import { AMAProvider } from '@react-native-ama/core'; | ||
import { StatusBar } from 'expo-status-bar'; | ||
import React from 'react'; | ||
import { GestureHandlerRootView } from 'react-native-gesture-handler'; | ||
|
||
import { AppNavigator } from './src/AppNavigation'; | ||
|
||
export default function App() { | ||
return ( | ||
<AMAProvider> | ||
<StatusBar style="auto" /> | ||
<AppNavigator /> | ||
</AMAProvider> | ||
<GestureHandlerRootView style={{ flex: 1 }}> | ||
<AMAProvider> | ||
<StatusBar style="auto" /> | ||
<AppNavigator /> | ||
</AMAProvider> | ||
</GestureHandlerRootView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ImageRequireSource } from 'react-native'; | ||
|
||
export const fox_1: ImageRequireSource = require('./fox-1.jpg'); | ||
export const fox_2: ImageRequireSource = require('./fox-2.jpg'); | ||
export const fox_3: ImageRequireSource = require('./fox-3.jpg'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Carousel } from '@react-native-ama/extras'; | ||
import * as React from 'react'; | ||
import { | ||
Image, | ||
ListRenderItem, | ||
Platform, | ||
SafeAreaView, | ||
StyleSheet, | ||
Text, | ||
View, | ||
useWindowDimensions, | ||
} from 'react-native'; | ||
import { FlatList } from 'react-native-gesture-handler'; | ||
|
||
import { fox_1, fox_2, fox_3 } from '../assets/images'; | ||
import { theme } from '../theme'; | ||
|
||
type Data = (typeof data)[number]; | ||
|
||
const isAndroid = Platform.OS === 'android'; | ||
|
||
const ITEM_SEPARATOR_WIDTH = 24; | ||
const IMAGE_WIDTH = 220; | ||
|
||
const data = [ | ||
{ key: '1', image: fox_1 }, | ||
{ key: '2', image: fox_2 }, | ||
{ key: '3', image: fox_3 }, | ||
]; | ||
|
||
const renderItem: ListRenderItem<Data> = ({ item }) => { | ||
return <Image source={item.image} resizeMode="cover" style={styles.image} />; | ||
}; | ||
|
||
export const CarouselScreen = () => { | ||
const ref = React.useRef<FlatList<Data>>(null); | ||
const { width } = useWindowDimensions(); | ||
|
||
const snapToOffsets = data.reduce((acc, _, index) => { | ||
if (index === 0) { | ||
return [...acc, 0]; | ||
} else if (index === 1) { | ||
return [ | ||
...acc, | ||
IMAGE_WIDTH + 2 * ITEM_SEPARATOR_WIDTH - (width - IMAGE_WIDTH) / 2, | ||
]; | ||
} else { | ||
return [ | ||
...acc, | ||
acc?.[acc.length - 1] + IMAGE_WIDTH + ITEM_SEPARATOR_WIDTH, | ||
]; | ||
} | ||
}, [] as number[]); | ||
return ( | ||
<SafeAreaView style={styles.wrapper}> | ||
<Carousel | ||
ref={ref} | ||
accessibilityLabel="Carousel of foxes" | ||
snapToOffsets={snapToOffsets} | ||
data={data} | ||
renderItem={renderItem} | ||
ItemSeparatorComponent={ItemSeparator} | ||
/> | ||
<Text style={styles.text}>{`The Carousel above is fully accessible, use ${ | ||
isAndroid ? 'TalkBack on Android' : 'VoiceOver on iOS' | ||
} to interact with it.`}</Text> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
const ItemSeparator: React.FC = () => ( | ||
<View style={{ width: ITEM_SEPARATOR_WIDTH }} /> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
wrapper: { | ||
paddingHorizontal: theme.padding.big, | ||
marginTop: theme.padding.big, | ||
}, | ||
image: { | ||
width: IMAGE_WIDTH, | ||
height: 300, | ||
borderRadius: 6, | ||
}, | ||
text: { | ||
marginTop: theme.padding.normal, | ||
fontSize: theme.fontSize.normal, | ||
textAlign: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters