-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcontext-playground.tsx
More file actions
146 lines (133 loc) · 5.08 KB
/
context-playground.tsx
File metadata and controls
146 lines (133 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from "react";
import { Platform, ScrollView, StyleSheet } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { ThemedText } from "@/components/themed-text";
import { ThemedView } from "@/components/themed-view";
import { BottomTabInset, MaxContentWidth, Spacing } from "@/constants/theme";
import { useTheme } from "@/hooks/use-theme";
import { ReactNativeGrabContextProvider, ReactNativeGrabScreen } from "react-native-grab";
const formatContext = (value: Record<string, string | number | boolean | null>) =>
JSON.stringify(value);
const ContextLabel = ({ value }: { value: Record<string, string | number | boolean | null> }) => {
return (
<ThemedView type="backgroundSelected" style={styles.contextLabel}>
<ThemedText type="code">adds: {formatContext(value)}</ThemedText>
</ThemedView>
);
};
export default function ContextPlaygroundScreen() {
const safeAreaInsets = useSafeAreaInsets();
const theme = useTheme();
const rootContext = { area: "context-playground", release: "1.0", tracked: true } as const;
const sectionContext = { section: "checkout-flow", density: "compact" } as const;
const cardContext = { card: "payment-summary", currency: "USD", experiment: "B" } as const;
const ctaContext = { action: "confirm-payment", priority: 1 } as const;
const contentPlatformStyle = Platform.select({
default: {
paddingTop: Spacing.three,
paddingBottom: safeAreaInsets.bottom + BottomTabInset + Spacing.three,
paddingLeft: safeAreaInsets.left,
paddingRight: safeAreaInsets.right,
},
android: {
paddingTop: Spacing.three,
paddingLeft: safeAreaInsets.left,
paddingRight: safeAreaInsets.right,
paddingBottom: safeAreaInsets.bottom + BottomTabInset + Spacing.three,
},
web: {
paddingTop: Spacing.six,
paddingBottom: Spacing.four,
},
});
return (
<ReactNativeGrabScreen>
<ScrollView
style={[styles.scrollView, { backgroundColor: theme.background }]}
contentContainerStyle={[styles.contentContainer, contentPlatformStyle]}
>
<ThemedView style={styles.container}>
<ThemedView style={styles.header}>
<ThemedText type="subtitle">Grab Context Playground</ThemedText>
<ThemedText themeColor="textSecondary">
Select any box below and verify the copied payload includes this hierarchy.
</ThemedText>
</ThemedView>
<ReactNativeGrabContextProvider value={rootContext}>
<ThemedView type="backgroundElement" style={styles.levelRoot}>
<ThemedText type="smallBold">Level 1: App Area</ThemedText>
<ContextLabel value={rootContext} />
<ReactNativeGrabContextProvider value={sectionContext}>
<ThemedView type="backgroundElement" style={styles.levelSection}>
<ThemedText type="smallBold">Level 2: Section</ThemedText>
<ContextLabel value={sectionContext} />
<ReactNativeGrabContextProvider value={cardContext}>
<ThemedView type="backgroundElement" style={styles.levelCard}>
<ThemedText type="smallBold">Level 3: Card</ThemedText>
<ContextLabel value={cardContext} />
<ReactNativeGrabContextProvider value={ctaContext}>
<ThemedView type="backgroundSelected" style={styles.levelAction}>
<ThemedText type="smallBold">Level 4: Action Button</ThemedText>
<ContextLabel value={ctaContext} />
<ThemedText type="small" themeColor="textSecondary">
Grab this node to get all levels merged.
</ThemedText>
</ThemedView>
</ReactNativeGrabContextProvider>
</ThemedView>
</ReactNativeGrabContextProvider>
</ThemedView>
</ReactNativeGrabContextProvider>
</ThemedView>
</ReactNativeGrabContextProvider>
</ThemedView>
</ScrollView>
</ReactNativeGrabScreen>
);
}
const styles = StyleSheet.create({
scrollView: {
flex: 1,
},
contentContainer: {
flexDirection: "row",
justifyContent: "center",
},
container: {
width: "100%",
maxWidth: MaxContentWidth,
paddingHorizontal: Spacing.four,
gap: Spacing.four,
},
header: {
gap: Spacing.one,
},
levelRoot: {
borderRadius: Spacing.three,
padding: Spacing.three,
gap: Spacing.two,
},
levelSection: {
borderRadius: Spacing.three,
padding: Spacing.three,
gap: Spacing.two,
marginTop: Spacing.one,
},
levelCard: {
borderRadius: Spacing.three,
padding: Spacing.three,
gap: Spacing.two,
marginTop: Spacing.one,
},
levelAction: {
borderRadius: Spacing.three,
padding: Spacing.three,
gap: Spacing.one,
marginTop: Spacing.one,
},
contextLabel: {
borderRadius: Spacing.two,
paddingHorizontal: Spacing.two,
paddingVertical: Spacing.one,
},
});