@@ -21,6 +21,7 @@ import {
2121 PlatformColor ,
2222 Pressable ,
2323 StyleSheet ,
24+ Switch ,
2425 Text ,
2526 View ,
2627} from 'react-native' ;
@@ -286,31 +287,22 @@ const scenarioReceiverStyle = {
286287 alignItems : 'flex-start' as const ,
287288} ;
288289
289- function Scenario ( {
290- label,
291- blockNativeResponder,
292- onNativeTouch,
293- onPressIn,
294- onPress,
295- } : {
296- label : string ,
297- blockNativeResponder ?: boolean ,
298- onNativeTouch : ( ) => void ,
299- onPressIn : ( ) => void ,
300- onPress : ( ) => void ,
301- } ) {
290+ function PressableBlockNativeResponderExample ( ) {
291+ const [ blockNativeResponder , setBlockNativeResponder ] = useState ( false ) ;
292+ const [ log , setLog ] = useState < Array < string >> ( [ ] ) ;
293+ const onNativeTouch = ( ) =>
294+ setLog ( prev => [ ...prev , 'NativeTouchReceiver.onNativeTouch' ] ) ;
295+ const onPressIn = ( ) => setLog ( [ ] ) ;
296+ const onPress = ( ) => setLog ( prev => [ ...prev , 'Pressable.onPress' ] ) ;
297+
302298 return (
303- < >
304- < Text
305- style = { {
306- fontSize : 13 ,
307- fontWeight : '600' ,
308- color : '#444' ,
309- marginTop : 10 ,
310- marginBottom : 4 ,
311- } } >
312- { label }
313- </ Text >
299+ < View >
300+ < View style = { { flexDirection : 'row' , alignItems : 'center' , marginBottom : 12 } } >
301+ < Text style = { { flex : 1 , fontSize : 13 , color : '#444' } } >
302+ blockNativeResponder
303+ </ Text >
304+ < Switch value = { blockNativeResponder } onValueChange = { setBlockNativeResponder } />
305+ </ View >
314306 < RNTNativeTouchReceiver
315307 style = { scenarioReceiverStyle }
316308 onNativeTouch = { onNativeTouch } >
@@ -325,36 +317,10 @@ function Scenario({
325317 onPressIn = { onPressIn }
326318 onPress = { onPress } >
327319 < Text style = { { color : '#fff' , fontWeight : '600' , fontSize : 15 } } >
328- Tap me
320+ Press Me
329321 </ Text >
330322 </ Pressable >
331323 </ RNTNativeTouchReceiver >
332- </ >
333- ) ;
334- }
335-
336- function PressablePreventNativePropagationExample ( ) {
337- const [ log , setLog ] = useState < Array < string >> ( [ ] ) ;
338- const onNativeTouch = ( ) =>
339- setLog ( prev => [ ...prev , 'NativeTouchReceiver.onNativeTouch' ] ) ;
340- const onPressIn = ( ) => setLog ( [ ] ) ;
341- const onPress = ( ) => setLog ( prev => [ ...prev , 'Pressable.onPress' ] ) ;
342-
343- return (
344- < View >
345- < Scenario
346- label = "blockNativeResponder={false} (default)"
347- onNativeTouch = { onNativeTouch }
348- onPressIn = { onPressIn }
349- onPress = { onPress }
350- />
351- < Scenario
352- label = "blockNativeResponder={true}"
353- blockNativeResponder = { true }
354- onNativeTouch = { onNativeTouch }
355- onPressIn = { onPressIn }
356- onPress = { onPress }
357- />
358324 < LogBox lines = { log } />
359325 </ View >
360326 ) ;
@@ -364,28 +330,16 @@ const monoFont = Platform.OS === 'ios' ? 'Menlo' : 'monospace';
364330
365331function LogBox ( { lines} : { lines : Array < string > } ) {
366332 return (
367- < View
368- style = { {
369- backgroundColor : '#1a1a1a' ,
370- borderRadius : 6 ,
371- padding : 10 ,
372- minHeight : 100 ,
373- marginBottom : 12 ,
374- } } >
333+ < View style = { styles . eventLogBox } >
375334 { lines . length === 0 ? (
376- < Text style = { { color : '#555 ' , fontSize : 12 , fontStyle : 'italic' } } >
335+ < Text style = { { color : '#999 ' , fontSize : 12 , fontStyle : 'italic' } } >
377336 tap to see events
378337 </ Text >
379338 ) : (
380339 lines . map ( ( line , i ) => (
381340 < Text
382341 key = { i }
383- style = { {
384- color : '#b5f5a0' ,
385- fontSize : 12 ,
386- fontFamily : monoFont ,
387- lineHeight : 17 ,
388- } } >
342+ style = { { fontSize : 12 , fontFamily : monoFont , lineHeight : 17 } } >
389343 { line }
390344 </ Text >
391345 ) )
@@ -787,7 +741,7 @@ const examples = [
787741 ' Pressable inside a native UIView parent . Without blockNativeResponder the touch leaks up the UIKit responder chain to the parent . ' as string,
788742 platform : ' ios ',
789743 render : function ( ) : React . Node {
790- return < PressablePreventNativePropagationExample /> ;
744+ return < PressableBlockNativeResponderExample /> ;
791745 } ,
792746 } ,
793747 ...PressableExampleFbInternal . examples ,
0 commit comments