Skip to content

Commit 40604ed

Browse files
committed
[test] Refactor TouchableScale component in example app
1 parent def68ac commit 40604ed

6 files changed

Lines changed: 26 additions & 24 deletions

File tree

example/src/components/Test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon } from "./Icon";
66

77
type Props = {
88
title: string;
9-
ComponentV4: React.ComponentType<any> | null;
9+
ComponentV4?: React.ComponentType<any> | null;
1010
Component?: React.ComponentType<any> | null;
1111
onPress?: () => any;
1212
v4?: boolean;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from "react";
2+
import { TouchableOpacity } from "react-native-gesture-handler";
3+
// @ts-ignore
4+
import RawTouchableScale from "react-native-touchable-scale";
5+
6+
type Props = React.ComponentProps<typeof TouchableOpacity> & {
7+
children: any;
8+
};
9+
10+
export function TouchableScale(props: Props) {
11+
return (
12+
<RawTouchableScale
13+
activeScale={0.9}
14+
tension={50}
15+
friction={7}
16+
useNativeDriver
17+
{...props}
18+
/>
19+
);
20+
}

example/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./Test";
33
export * from "./Tests";
44
export * from "./Colors";
55
export * from "./TabBarIcon";
6+
export * from "./TouchableScale";

example/src/screens/CardItem.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from "react";
22
import { View, StyleSheet, Text, Image, Platform } from "react-native";
3-
// @ts-ignore
4-
import TouchableScale from "react-native-touchable-scale";
53
import { SharedElement } from "react-navigation-shared-element";
64
import { NavigationStackProp } from "react-navigation-stack";
75

6+
import { TouchableScale } from "../components";
87
import { Item } from "../data";
98

109
type Props = {
@@ -17,10 +16,6 @@ export function CardItem(props: Props) {
1716
const { item, navigation, routeName = "Detail" } = props;
1817
return (
1918
<TouchableScale
20-
activeScale={0.9}
21-
tension={50}
22-
friction={7}
23-
useNativeDriver
2419
onPress={() =>
2520
navigation.navigate(routeName, {
2621
item,
@@ -31,7 +26,6 @@ export function CardItem(props: Props) {
3126
<SharedElement id={`${item.id}.card`} style={StyleSheet.absoluteFill}>
3227
<View style={styles.card} />
3328
</SharedElement>
34-
3529
<SharedElement id={`${item.id}.image`} style={styles.imageContainer}>
3630
<Image style={styles.image} source={item.image} />
3731
</SharedElement>

example/src/screens/ListScreen.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from "react";
22
import { StyleSheet, Image, FlatList, Text } from "react-native";
3-
// @ts-ignore
4-
import TouchableScale from "react-native-touchable-scale";
53
import { SharedElement } from "react-navigation-shared-element";
64
import { NavigationStackProp } from "react-navigation-stack";
75

6+
import { TouchableScale } from "../components";
87
import { items, Item } from "../data";
98

109
type Props = {
@@ -35,10 +34,6 @@ export class ListScreen extends React.Component<Props> {
3534
return (
3635
<TouchableScale
3736
style={styles.item}
38-
activeScale={0.9}
39-
tension={50}
40-
friction={7}
41-
useNativeDriver
4237
onPress={() => {
4338
navigation.navigate(routeName, {
4439
item,

example/src/screens/MainScreen.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from "react";
22
import { View, StyleSheet, Text, Image } from "react-native";
3-
// @ts-ignore
4-
import TouchableScale from "react-native-touchable-scale";
53
import { SharedElement } from "react-navigation-shared-element";
64
import { NavigationStackProp } from "react-navigation-stack";
75

6+
import { TouchableScale } from "../components";
87
import { defaultItem, Item } from "../data";
98

109
type Props = {
@@ -24,14 +23,7 @@ export class MainScreen extends React.Component<Props> {
2423
const item: Item = params?.item || defaultItem;
2524
return (
2625
<>
27-
<TouchableScale
28-
style={styles.flex}
29-
activeScale={0.9}
30-
tension={50}
31-
friction={7}
32-
useNativeDriver
33-
onPress={this.onPress}
34-
>
26+
<TouchableScale style={styles.flex} onPress={this.onPress}>
3527
<View style={styles.container}>
3628
<SharedElement id={`${item.id}.image`}>
3729
<Image style={styles.image} source={item.image} />

0 commit comments

Comments
 (0)