Repository navigation
Conversation
|
On this PR's head (664c6aa), an I built RNTester's release APK (arm64-v8a) from 664c6aa with this component registered as import * as React from 'react';
import {useEffect, useRef, useState} from 'react';
import {
findNodeHandle,
Image,
Pressable,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
export default function ImageNextFocus() {
const imageRef = useRef(null);
const [imageTag, setImageTag] = useState(undefined);
const [named, setNamed] = useState(true);
const [focused, setFocused] = useState('none');
const [submits, setSubmits] = useState(0);
useEffect(() => {
setImageTag(findNodeHandle(imageRef.current) ?? undefined);
}, []);
const track = name => ({
onBlur: () => setFocused(current => (current === name ? 'none' : current)),
onFocus: () => setFocused(name),
});
const target = named ? imageTag : undefined;
return (
<View style={styles.root}>
<Text testID="state">{`Focused: ${focused}; submits: ${submits}; image tag: ${String(imageTag)}; named: ${String(named)}`}</Text>
<TextInput
nextFocusForward={target}
onSubmitEditing={() => setSubmits(count => count + 1)}
placeholder="input"
returnKeyType="next"
style={styles.input}
testID="input"
{...track('input')}
/>
<Pressable
accessibilityLabel="source"
nextFocusDown={target}
nextFocusForward={target}
onPress={() => {}}
style={styles.box}
testID="source"
{...track('source')}>
<Text>source</Text>
</Pressable>
<Image
accessibilityLabel="image"
accessible={true}
focusable={false}
ref={imageRef}
source={require('./assets/bunny.png')}
style={styles.image}
testID="image"
/>
<Pressable
accessibilityLabel="after"
onPress={() => {}}
style={styles.box}
testID="after"
{...track('after')}>
<Text>after</Text>
</Pressable>
<Pressable
accessible={false}
focusable={false}
onPress={() => setNamed(value => !value)}
style={styles.toggle}
testID="toggle">
<Text>{named ? 'unname the image' : 'name the image'}</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
root: {padding: 8, paddingTop: 48},
input: {borderWidth: 1, height: 44, marginVertical: 4},
box: {borderWidth: 1, height: 44, justifyContent: 'center', marginVertical: 4, padding: 4},
image: {height: 44, marginVertical: 4, width: 44},
toggle: {backgroundColor: '#ddd', height: 44, justifyContent: 'center', marginTop: 16, padding: 4},
});
Expected: in step 2 focus moves from Actual, the focused node in the view tree after each key:
|
|
Good catch, you're right. I pushed d19f38a so an excluded image now hands focus to the next focusable view instead of refusing it. I couldn't run the Gradle tests here, so the new test is unverified. |
Visual regressionNo visual differences at |
Summary:
On Android, an accessible
Imagestill takes hardware-keyboard focus withfocusable={false}ortabIndex={-1}.setAccessiblesetsisFocusable, which keyboard navigation also reads, andReactImageManagerhad nofocusablesetter, so the prop did nothing.Image.android.jsalso never turnedtabIndexintofocusablethe wayViewdoes.ReactImageManagernow handlesfocusable, andReactImageViewleaves itself out ofaddFocusablesand refusesrequestFocuswhen it isfalse.isFocusablestays tied toaccessible, so TalkBack still reaches the image. A focused image stays a candidate so focus can move on from it.Image.android.jsmapstabIndextofocusablelikeView.js. This is theImageside of #59048 (View) and #59139 (Text).Fixes #60168
Changelog:
[ANDROID] [FIXED] -
focusable={false}andtabIndex={-1}take an accessibleImageout of hardware-keyboard navigationTest Plan:
Added
testFocusableFalseKeepsAccessibleImageOutOfKeyboardFocustoReactImagePropertyTest. It setsaccessibleandfocusable={false}throughupdateProperties, then checks thataddFocusablesadds nothing,requestFocusfails andisFocusablestays true, and thatfocusable={true}makes the image a candidate again. It fails onmainand passes with the change.The full ReactAndroid unit test suite passes, and
format-check-kotlin, ESLint, Prettier andflow full-checkare clean. I didn't run the reproducer on a device.