@@ -14,6 +14,7 @@ import type {RNTesterModule} from '../../types/RNTesterTypes';
1414
1515import RNTesterText from '../../components/RNTesterText' ;
1616import * as React from 'react' ;
17+ import { useState } from 'react' ;
1718import {
1819 Platform ,
1920 PlatformColor ,
@@ -699,6 +700,74 @@ function BoxSizingExample(): React.Node {
699700 ) ;
700701}
701702
703+ function FocusableInnerRow ( { focusable} : { focusable : boolean } ) {
704+ const styles = StyleSheet . create ( {
705+ focused : {
706+ borderColor : 'blue' ,
707+ borderWidth : 2 ,
708+ } ,
709+ innerBox : {
710+ backgroundColor : 'red' ,
711+ width : '100%' ,
712+ height : 50 ,
713+ borderColor : 'transparent' ,
714+ borderWidth : 2 ,
715+ } ,
716+ innerBoxTextColor : {
717+ color : 'white' ,
718+ } ,
719+ } ) ;
720+ const [ focused , setFocused ] = useState ( false ) ;
721+ return (
722+ < View
723+ accessible = { focusable }
724+ focusable = { focusable }
725+ onBlur = { ( ) => setFocused ( false ) }
726+ onFocus = { ( ) => setFocused ( true ) }
727+ style = { [ styles . innerBox , focused && styles . focused ] } >
728+ < RNTesterText style = { styles . innerBoxTextColor } >
729+ Focusable: { focusable ? 'true' : 'false' }
730+ </ RNTesterText >
731+ < RNTesterText style = { styles . innerBoxTextColor } >
732+ Focused: { focused ? 'true' : 'false' }
733+ </ RNTesterText >
734+ </ View >
735+ ) ;
736+ }
737+
738+ function FocusBlurExample ( ) : React . Node {
739+ const styles = StyleSheet . create ( {
740+ focused : {
741+ borderColor : 'blue' ,
742+ borderWidth : 2 ,
743+ } ,
744+ outerBox : {
745+ backgroundColor : 'green' ,
746+ borderColor : 'transparent' ,
747+ borderWidth : 2 ,
748+ padding : 10 ,
749+ } ,
750+ outerBoxTextColor : {
751+ color : 'white' ,
752+ } ,
753+ } ) ;
754+ const [ outerFocused , setOuterFocused ] = useState ( false ) ;
755+ return (
756+ < View
757+ onBlur = { ( ) => setOuterFocused ( false ) }
758+ onFocus = { ( ) => setOuterFocused ( true ) }
759+ style = { [ styles . outerBox , outerFocused && styles . focused ] } >
760+ < RNTesterText style = { styles . outerBoxTextColor } >
761+ Focused: { outerFocused ? 'true' : 'false' }
762+ </ RNTesterText >
763+ < FocusableInnerRow focusable = { true } />
764+ < FocusableInnerRow focusable = { true } />
765+ < FocusableInnerRow focusable = { false } />
766+ < FocusableInnerRow focusable = { true } />
767+ </ View >
768+ ) ;
769+ }
770+
702771export default ( {
703772 title : 'View' ,
704773 documentationURL : 'https://reactnative.dev/docs/view' ,
@@ -1363,5 +1432,10 @@ export default ({
13631432 name : 'box - sizing ',
13641433 render : BoxSizingExample ,
13651434 } ,
1435+ {
1436+ title : 'Focus / Blur ',
1437+ name : 'focus - blur ',
1438+ render : FocusBlurExample ,
1439+ } ,
13661440 ] ,
13671441} : RNTesterModule ) ;
0 commit comments