|
| 1 | +/** |
| 2 | + * Touch Test Demo |
| 3 | + * |
| 4 | + * Single scrollable page combining Touch Bleed and Overlay tests. |
| 5 | + * Minimal host views to keep tag values low and predictable. |
| 6 | + */ |
| 7 | +import SandboxReactNativeView from '@callstack/react-native-sandbox' |
| 8 | +import React, {useState} from 'react' |
| 9 | +import { |
| 10 | + SafeAreaView, |
| 11 | + ScrollView, |
| 12 | + StyleSheet, |
| 13 | + Text, |
| 14 | + TouchableOpacity, |
| 15 | + View, |
| 16 | +} from 'react-native' |
| 17 | + |
| 18 | +// ─── Padding helper ───────────────────────────────────────────────────────── |
| 19 | + |
| 20 | +function TagPadding({count}: {count: number}) { |
| 21 | + return ( |
| 22 | + <> |
| 23 | + {Array.from({length: count}, (_, i) => ( |
| 24 | + <View key={i} style={styles.pad} /> |
| 25 | + ))} |
| 26 | + </> |
| 27 | + ) |
| 28 | +} |
| 29 | + |
| 30 | +// ─── App ──────────────────────────────────────────────────────────────────── |
| 31 | + |
| 32 | +export default function App() { |
| 33 | + const [pressCount, setPressCount] = useState(0) |
| 34 | + const [hostTag, setHostTag] = useState<number | null>(null) |
| 35 | + const [overlayVisible, setOverlayVisible] = useState(false) |
| 36 | + const [overlayPressCount, setOverlayPressCount] = useState(0) |
| 37 | + const [overlayBtnTag, setOverlayBtnTag] = useState<number | null>(null) |
| 38 | + |
| 39 | + return ( |
| 40 | + <SafeAreaView style={styles.container}> |
| 41 | + <ScrollView> |
| 42 | + {/* ── Test 1: Touch Bleed ── */} |
| 43 | + <View style={styles.section}> |
| 44 | + <Text style={styles.title}>Test 1: Touch Bleed</Text> |
| 45 | + <Text style={styles.description}> |
| 46 | + Press a sandbox button whose tag matches the host button tag. Watch |
| 47 | + if the host button highlights or press count increases. |
| 48 | + </Text> |
| 49 | + |
| 50 | + <TagPadding count={10} /> |
| 51 | + |
| 52 | + <TouchableOpacity |
| 53 | + style={styles.hostButton} |
| 54 | + onLayout={e => { |
| 55 | + const tag = (e as any).nativeEvent?.target |
| 56 | + if (tag != null) setHostTag(tag) |
| 57 | + }} |
| 58 | + onPress={() => setPressCount(c => c + 1)}> |
| 59 | + <Text style={styles.buttonText}> |
| 60 | + Host Button{hostTag != null ? ` (tag: ${hostTag})` : ''} |
| 61 | + </Text> |
| 62 | + </TouchableOpacity> |
| 63 | + <Text style={styles.result}> |
| 64 | + Press count: {pressCount}{' '} |
| 65 | + {pressCount > 0 ? '❌ BLEED DETECTED' : '✅ No bleed'} |
| 66 | + </Text> |
| 67 | + </View> |
| 68 | + |
| 69 | + <View style={styles.sandboxSection}> |
| 70 | + <Text style={styles.sectionHeader}>Sandbox (Touch Bleed)</Text> |
| 71 | + <SandboxReactNativeView |
| 72 | + style={styles.sandbox} |
| 73 | + componentName={'SandboxedDemo'} |
| 74 | + jsBundleSource={'sandbox.android.bundle'} |
| 75 | + onError={error => console.warn('Sandbox error:', error)} |
| 76 | + /> |
| 77 | + </View> |
| 78 | + |
| 79 | + <View style={styles.divider} /> |
| 80 | + |
| 81 | + {/* ── Test 2: Overlay over Sandbox ── */} |
| 82 | + <View style={styles.section}> |
| 83 | + <Text style={styles.title}>Test 2: Overlay over Sandbox</Text> |
| 84 | + <Text style={styles.description}> |
| 85 | + Tests that host views rendered on top of a sandbox correctly receive |
| 86 | + touches without bleeding into sandbox buttons.{'\n\n'} |
| 87 | + Expected behavior:{'\n'}• Overlay buttons — should fire (count |
| 88 | + increments){'\n'}• Card area over sandbox — should NOT fire sandbox |
| 89 | + buttons{'\n'}• Grey backdrop — should block sandbox touches{'\n'}• |
| 90 | + Top-half sandbox buttons (no overlay) — should work normally |
| 91 | + </Text> |
| 92 | + |
| 93 | + <TouchableOpacity |
| 94 | + style={styles.actionButton} |
| 95 | + onLayout={e => { |
| 96 | + const tag = (e as any).nativeEvent?.target |
| 97 | + if (tag != null) setOverlayBtnTag(tag) |
| 98 | + }} |
| 99 | + onPress={() => setOverlayVisible(v => !v)}> |
| 100 | + <Text style={styles.buttonText}> |
| 101 | + {overlayVisible ? 'Hide Overlay' : 'Show Overlay'} |
| 102 | + {overlayBtnTag != null ? ` (tag: ${overlayBtnTag})` : ''} |
| 103 | + </Text> |
| 104 | + </TouchableOpacity> |
| 105 | + |
| 106 | + <Text style={styles.result}> |
| 107 | + Overlay presses: {overlayPressCount} |
| 108 | + {overlayPressCount > 0 ? ' ✅' : ''} |
| 109 | + </Text> |
| 110 | + </View> |
| 111 | + |
| 112 | + <View style={styles.sandboxSection}> |
| 113 | + <Text style={styles.sectionHeader}>Sandbox (Overlay)</Text> |
| 114 | + <View style={{position: 'relative'}}> |
| 115 | + <SandboxReactNativeView |
| 116 | + style={styles.sandbox} |
| 117 | + componentName={'SandboxedDemo'} |
| 118 | + jsBundleSource={'sandbox.android.bundle'} |
| 119 | + onError={error => console.warn('Sandbox error:', error)} |
| 120 | + /> |
| 121 | + {overlayVisible && ( |
| 122 | + <View style={overlayStyles.backdrop}> |
| 123 | + <View style={overlayStyles.card}> |
| 124 | + <Text style={overlayStyles.cardTitle}>Host Overlay</Text> |
| 125 | + <Text style={overlayStyles.cardDesc}> |
| 126 | + This view is rendered by the host ON TOP of the sandbox. |
| 127 | + Tapping the button below should work normally. |
| 128 | + </Text> |
| 129 | + <TouchableOpacity |
| 130 | + style={overlayStyles.overlayButton} |
| 131 | + onPress={() => setOverlayPressCount(c => c + 1)}> |
| 132 | + <Text style={styles.buttonText}> |
| 133 | + Tap Me (overlay) — count: {overlayPressCount} |
| 134 | + </Text> |
| 135 | + </TouchableOpacity> |
| 136 | + <TouchableOpacity |
| 137 | + style={[ |
| 138 | + overlayStyles.overlayButton, |
| 139 | + {backgroundColor: '#ff3b30', marginTop: 8}, |
| 140 | + ]} |
| 141 | + onPress={() => setOverlayVisible(false)}> |
| 142 | + <Text style={styles.buttonText}>Dismiss</Text> |
| 143 | + </TouchableOpacity> |
| 144 | + </View> |
| 145 | + </View> |
| 146 | + )} |
| 147 | + </View> |
| 148 | + </View> |
| 149 | + </ScrollView> |
| 150 | + </SafeAreaView> |
| 151 | + ) |
| 152 | +} |
| 153 | + |
| 154 | +// ─── Styles ───────────────────────────────────────────────────────────────── |
| 155 | + |
| 156 | +const overlayStyles = StyleSheet.create({ |
| 157 | + backdrop: { |
| 158 | + position: 'absolute', |
| 159 | + top: '50%', |
| 160 | + left: '15%', |
| 161 | + right: '15%', |
| 162 | + bottom: 0, |
| 163 | + backgroundColor: 'rgba(0,0,0,0.3)', |
| 164 | + justifyContent: 'center', |
| 165 | + alignItems: 'center', |
| 166 | + zIndex: 10, |
| 167 | + elevation: 0, |
| 168 | + }, |
| 169 | + card: { |
| 170 | + backgroundColor: '#fff', |
| 171 | + borderRadius: 12, |
| 172 | + borderWidth: 1, |
| 173 | + borderColor: '#000000ff', |
| 174 | + padding: 24, |
| 175 | + width: '65%', |
| 176 | + marginTop: -150, |
| 177 | + shadowColor: '#000', |
| 178 | + shadowOffset: {width: 0, height: 4}, |
| 179 | + shadowOpacity: 0.3, |
| 180 | + shadowRadius: 8, |
| 181 | + elevation: 12, |
| 182 | + }, |
| 183 | + cardTitle: { |
| 184 | + fontSize: 18, |
| 185 | + fontWeight: '700', |
| 186 | + marginBottom: 8, |
| 187 | + }, |
| 188 | + cardDesc: { |
| 189 | + fontSize: 14, |
| 190 | + color: '#666', |
| 191 | + marginBottom: 16, |
| 192 | + lineHeight: 20, |
| 193 | + }, |
| 194 | + overlayButton: { |
| 195 | + backgroundColor: '#34c759', |
| 196 | + paddingVertical: 14, |
| 197 | + borderRadius: 8, |
| 198 | + alignItems: 'center', |
| 199 | + }, |
| 200 | +}) |
| 201 | + |
| 202 | +const styles = StyleSheet.create({ |
| 203 | + container: { |
| 204 | + flex: 1, |
| 205 | + backgroundColor: '#fff', |
| 206 | + }, |
| 207 | + section: { |
| 208 | + padding: 16, |
| 209 | + }, |
| 210 | + title: { |
| 211 | + fontSize: 20, |
| 212 | + fontWeight: '700', |
| 213 | + marginBottom: 8, |
| 214 | + }, |
| 215 | + sectionHeader: { |
| 216 | + fontSize: 16, |
| 217 | + fontWeight: '600', |
| 218 | + marginBottom: 8, |
| 219 | + }, |
| 220 | + description: { |
| 221 | + fontSize: 14, |
| 222 | + color: '#666', |
| 223 | + marginBottom: 16, |
| 224 | + lineHeight: 20, |
| 225 | + }, |
| 226 | + pad: { |
| 227 | + height: 1, |
| 228 | + }, |
| 229 | + hostButton: { |
| 230 | + backgroundColor: '#007aff', |
| 231 | + paddingVertical: 14, |
| 232 | + borderRadius: 8, |
| 233 | + alignItems: 'center', |
| 234 | + marginBottom: 8, |
| 235 | + }, |
| 236 | + actionButton: { |
| 237 | + backgroundColor: '#5856d6', |
| 238 | + paddingVertical: 12, |
| 239 | + borderRadius: 8, |
| 240 | + alignItems: 'center', |
| 241 | + marginTop: 12, |
| 242 | + marginBottom: 8, |
| 243 | + }, |
| 244 | + buttonText: { |
| 245 | + color: '#fff', |
| 246 | + fontWeight: '600', |
| 247 | + fontSize: 16, |
| 248 | + }, |
| 249 | + result: { |
| 250 | + fontSize: 15, |
| 251 | + marginVertical: 4, |
| 252 | + }, |
| 253 | + sandboxSection: { |
| 254 | + padding: 16, |
| 255 | + borderTopWidth: 1, |
| 256 | + borderTopColor: '#ccc', |
| 257 | + }, |
| 258 | + sandbox: { |
| 259 | + height: 400, |
| 260 | + borderWidth: 1, |
| 261 | + borderColor: '#8232ff', |
| 262 | + borderRadius: 4, |
| 263 | + }, |
| 264 | + divider: { |
| 265 | + height: 8, |
| 266 | + backgroundColor: '#f0f0f0', |
| 267 | + marginVertical: 8, |
| 268 | + }, |
| 269 | +}) |
0 commit comments