Skip to content

Commit def68ac

Browse files
committed
[test] Enable paging on both card and list tests, in example app
1 parent 7a9c635 commit def68ac

17 files changed

+241
-354
lines changed

example/src/App.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import NestedStack from "./tests/NestedStack";
3131
import NestedStackV4 from "./tests/NestedStack.v4";
3232
import NestedStack2 from "./tests/NestedStack2";
3333
import NestedStack2V4 from "./tests/NestedStack2.v4";
34-
import PagerView from "./tests/PagerView";
35-
import PagerViewV4 from "./tests/PagerView.v4";
3634
import RevealFromBottomAndroid from "./tests/RevealFromBottomAndroid";
3735
import RevealFromBottomAndroidV4 from "./tests/RevealFromBottomAndroid.v4";
3836
import ScaleFromCenterAndroid from "./tests/ScaleFromCenterAndroid";
@@ -58,7 +56,6 @@ export default () => (
5856
/>
5957
<Test title="CardView" ComponentV4={CardViewV4} Component={CardView} />
6058
<Test title="ListView" ComponentV4={ListViewV4} Component={ListView} />
61-
<Test title="PagerView" ComponentV4={PagerViewV4} Component={PagerView} />
6259
<Test
6360
title="SlideFromRightIOS"
6461
ComponentV4={SlideFromRightIOSV4}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { LinearGradient } from "expo-linear-gradient";
2+
import * as React from "react";
3+
import { View, StyleSheet, Text, Image, TouchableOpacity } from "react-native";
4+
import { SharedElement } from "react-navigation-shared-element";
5+
import { NavigationStackProp } from "react-navigation-stack";
6+
7+
import { Icon } from "../components";
8+
import { Item } from "../data";
9+
10+
type Props = {
11+
navigation: NavigationStackProp<any>;
12+
item: Item;
13+
modal: "none" | "full" | "sheet";
14+
};
15+
16+
export const DetailComponent = (props: Props) => {
17+
const { item, navigation, modal = "none" } = props;
18+
return (
19+
<View style={styles.container}>
20+
<SharedElement id={`${item.id}.image`} style={StyleSheet.absoluteFill}>
21+
<Image style={styles.image} resizeMode="cover" source={item.image} />
22+
</SharedElement>
23+
24+
<SharedElement id={`${item.id}.logo`} style={styles.logoContainer}>
25+
<Image
26+
style={styles.logo}
27+
resizeMode="contain"
28+
source={require("../../assets/logo.png")}
29+
/>
30+
</SharedElement>
31+
32+
<View style={styles.content}>
33+
<SharedElement
34+
id={`${item.id}.gradient`}
35+
style={StyleSheet.absoluteFill}
36+
>
37+
<LinearGradient
38+
colors={["transparent", "rgba(0,0,0,0.9)"]}
39+
style={StyleSheet.absoluteFill}
40+
/>
41+
</SharedElement>
42+
<SharedElement id={`${item.id}.title`}>
43+
<Text style={styles.title}>{item.title}</Text>
44+
</SharedElement>
45+
46+
<SharedElement id={`${item.id}.description`}>
47+
<Text style={styles.description}>{item.description}</Text>
48+
</SharedElement>
49+
</View>
50+
51+
{modal !== "none" ? (
52+
<View
53+
style={[
54+
styles.header,
55+
modal === "sheet" ? styles.sheetHeader : undefined,
56+
]}
57+
>
58+
<TouchableOpacity
59+
activeOpacity={0.5}
60+
onPress={() => navigation.goBack()}
61+
>
62+
<SharedElement id="close">
63+
<Icon style={styles.icon} name="ios-close" />
64+
</SharedElement>
65+
</TouchableOpacity>
66+
</View>
67+
) : undefined}
68+
</View>
69+
);
70+
};
71+
72+
const styles = StyleSheet.create({
73+
container: {
74+
flex: 1,
75+
alignItems: "center",
76+
},
77+
header: {
78+
position: "absolute",
79+
right: 16,
80+
top: 32,
81+
},
82+
sheetHeader: {
83+
right: 16,
84+
top: 16,
85+
},
86+
icon: {
87+
fontSize: 40,
88+
color: "white",
89+
},
90+
image: {
91+
width: "100%",
92+
height: "100%",
93+
},
94+
logoContainer: {
95+
position: "absolute",
96+
left: 4,
97+
top: 12,
98+
height: 60,
99+
width: 160,
100+
},
101+
logo: {
102+
width: "100%",
103+
height: "100%",
104+
},
105+
content: {
106+
position: "absolute",
107+
left: 0,
108+
right: 0,
109+
bottom: 0,
110+
padding: 20,
111+
},
112+
title: {
113+
marginTop: 20,
114+
color: "white",
115+
fontSize: 60,
116+
fontWeight: "bold",
117+
textShadowColor: "black",
118+
textShadowRadius: 8,
119+
textShadowOffset: {
120+
width: 0,
121+
height: 1,
122+
},
123+
},
124+
description: {
125+
color: "white",
126+
fontSize: 17,
127+
fontWeight: "bold",
128+
textShadowColor: "black",
129+
textShadowRadius: 4,
130+
textShadowOffset: {
131+
width: 0,
132+
height: 1,
133+
},
134+
},
135+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import * as React from "react";
2+
import { StyleSheet, View } from "react-native";
3+
import PagerView, {
4+
PagerViewOnPageSelectedEvent,
5+
} from "react-native-pager-view";
6+
import { SharedElementsComponentConfig } from "react-navigation-shared-element";
7+
import { NavigationStackProp } from "react-navigation-stack";
8+
9+
import { Item, items } from "../data";
10+
import { DetailComponent } from "./DetailComponent";
11+
import { getDetailSharedElements } from "./getDetailSharedElements";
12+
13+
type Props = {
14+
navigation: NavigationStackProp<any>;
15+
route: any;
16+
};
17+
18+
export class DetailPagerScreen extends React.Component<Props> {
19+
static sharedElements: SharedElementsComponentConfig =
20+
getDetailSharedElements;
21+
22+
render() {
23+
const { navigation, route } = this.props;
24+
const params = route?.params || navigation?.state?.params;
25+
const initialItem: Item = params?.item;
26+
const initialIndex = items.indexOf(initialItem);
27+
return (
28+
<PagerView
29+
style={styles.container}
30+
initialPage={initialIndex}
31+
onPageSelected={this.onPageSelected}
32+
>
33+
{items.map((item) => this.renderItem(item))}
34+
</PagerView>
35+
);
36+
}
37+
38+
private renderItem(item: Item) {
39+
return (
40+
<View key={item.id} style={styles.container}>
41+
<DetailComponent
42+
item={item}
43+
navigation={this.props.navigation}
44+
modal="none"
45+
/>
46+
</View>
47+
);
48+
}
49+
50+
private onPageSelected = (e: PagerViewOnPageSelectedEvent) => {
51+
const { position } = e.nativeEvent;
52+
const { navigation } = this.props;
53+
navigation.setParams({
54+
item: items[position],
55+
});
56+
};
57+
}
58+
59+
const styles = StyleSheet.create({
60+
container: {
61+
flex: 1,
62+
},
63+
});

0 commit comments

Comments
 (0)