Skip to content

Commit e357e7c

Browse files
committed
Showcase example
1 parent 5005665 commit e357e7c

4 files changed

Lines changed: 435 additions & 21 deletions

File tree

Lines changed: 134 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,166 @@
11
import React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
2+
import { ScrollView, StyleSheet, Text, View } from 'react-native';
33
import Animated from 'react-native-reanimated';
44

5-
export default function PseudoActiveExample() {
5+
function BasicExample() {
66
return (
7-
<View style={styles.container}>
8-
<Text style={styles.label}>Press and hold the box</Text>
7+
<View style={styles.section}>
8+
<Text style={styles.sectionTitle}>Basic</Text>
9+
<Text style={styles.hint}>Press and hold</Text>
910
<Animated.View
1011
style={{
1112
...styles.box,
12-
transitionDuration: '1000ms',
13+
transitionDuration: '180ms',
1314
transitionTimingFunction: 'ease-in-out',
1415
opacity: { default: 1, ':active': 0.6 },
1516
transform: {
1617
default: [{ scale: 1 }, { rotate: '0deg' }],
1718
':active': [{ scale: 0.7 }, { rotate: '45deg' }],
1819
},
19-
backgroundColor: { default: '#4a90e2', ':active': 'pink' },
20+
backgroundColor: { default: '#4a90e2', ':active': '#e84393' },
2021
}}
2122
/>
22-
<Text style={styles.description}>
23-
Style changes happen in C++ on UI thread.{'\n'}
24-
No JS frame should appear on the profiler.
23+
</View>
24+
);
25+
}
26+
27+
function TargetingExample() {
28+
return (
29+
<View style={styles.section}>
30+
<Text style={styles.sectionTitle}>Bottommost element wins</Text>
31+
<Text style={styles.hint}>
32+
Unlike on the web where <Text style={styles.code}>:active</Text>{' '}
33+
propagates to all ancestors, here only the deepest element with{' '}
34+
<Text style={styles.code}>:active</Text> gets activated.{'\n\n'}
35+
Press a button → only the button activates.{'\n'}
36+
Press the card background → only the card activates.
2537
</Text>
38+
39+
<Animated.View
40+
style={{
41+
...styles.card,
42+
backgroundColor: { default: '#fff', ':active': '#fff3cd' },
43+
transform: {
44+
default: [{ scale: 1 }],
45+
':active': [{ scale: 0.97 }],
46+
},
47+
transitionDuration: '120ms',
48+
}}>
49+
<Text style={styles.cardLabel}>Card (has :active)</Text>
50+
<View style={styles.row}>
51+
<Animated.View
52+
style={{
53+
...styles.pill,
54+
backgroundColor: { default: '#4a90e2', ':active': '#1a5fb4' },
55+
transform: {
56+
default: [{ scale: 1 }],
57+
':active': [{ scale: 0.88 }],
58+
},
59+
transitionDuration: '100ms',
60+
}}>
61+
<Text style={styles.pillText}>Button A</Text>
62+
</Animated.View>
63+
<Animated.View
64+
style={{
65+
...styles.pill,
66+
backgroundColor: { default: '#e74c3c', ':active': '#922b21' },
67+
transform: {
68+
default: [{ scale: 1 }],
69+
':active': [{ scale: 0.88 }],
70+
},
71+
transitionDuration: '100ms',
72+
}}>
73+
<Text style={styles.pillText}>Button B</Text>
74+
</Animated.View>
75+
</View>
76+
<Text style={styles.cardHint}>← press here to activate card</Text>
77+
</Animated.View>
2678
</View>
2779
);
2880
}
2981

82+
export default function PseudoActiveExample() {
83+
return (
84+
<ScrollView contentContainerStyle={styles.screen}>
85+
<BasicExample />
86+
<TargetingExample />
87+
<Text style={styles.footer}>
88+
All transitions run on the UI thread - no JS frames.
89+
</Text>
90+
</ScrollView>
91+
);
92+
}
93+
3094
const styles = StyleSheet.create({
31-
container: {
32-
flex: 1,
33-
alignItems: 'center',
34-
justifyContent: 'center',
35-
gap: 24,
95+
screen: {
3696
padding: 20,
97+
gap: 32,
98+
paddingBottom: 48,
3799
},
38-
label: {
39-
fontSize: 16,
40-
fontWeight: '600',
100+
section: {
101+
gap: 12,
102+
},
103+
sectionTitle: {
104+
fontSize: 17,
105+
fontWeight: '700',
106+
color: '#111',
107+
},
108+
hint: {
109+
fontSize: 13,
110+
color: '#666',
111+
lineHeight: 20,
112+
},
113+
code: {
114+
fontFamily: 'monospace',
115+
color: '#4a90e2',
41116
},
42117
box: {
43118
width: 150,
44119
height: 150,
45120
borderRadius: 16,
121+
alignSelf: 'center',
46122
},
47-
description: {
48-
textAlign: 'center',
49-
color: '#666',
123+
124+
card: {
125+
borderRadius: 16,
126+
padding: 16,
127+
gap: 12,
128+
borderWidth: 1,
129+
borderColor: '#e8e8e8',
130+
shadowColor: '#000',
131+
shadowOffset: { width: 0, height: 2 },
132+
shadowOpacity: 0.06,
133+
shadowRadius: 8,
134+
elevation: 2,
135+
},
136+
cardLabel: {
137+
fontSize: 13,
138+
fontWeight: '600',
139+
color: '#999',
140+
},
141+
row: {
142+
flexDirection: 'row',
143+
gap: 10,
144+
},
145+
pill: {
146+
paddingHorizontal: 20,
147+
paddingVertical: 10,
148+
borderRadius: 100,
149+
},
150+
pillText: {
151+
color: '#fff',
152+
fontWeight: '600',
50153
fontSize: 14,
51-
lineHeight: 22,
154+
},
155+
cardHint: {
156+
fontSize: 12,
157+
color: '#bbb',
158+
fontStyle: 'italic',
159+
},
160+
footer: {
161+
textAlign: 'center',
162+
fontSize: 12,
163+
color: '#aaa',
164+
fontFamily: 'monospace',
52165
},
53166
});

0 commit comments

Comments
 (0)