Skip to content

Keep focusable={false} Android images out of keyboard navigation - #60172

Open
lazerg wants to merge 3 commits into
react:mainfrom
lazerg:fix/issue-60168-image-focusable
Open

lazerg wants to merge 3 commits into
react:mainfrom
lazerg:fix/issue-60168-image-focusable

Conversation

@lazerg

@lazerg lazerg commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary:

On Android, an accessible Image still takes hardware-keyboard focus with focusable={false} or tabIndex={-1}. setAccessible sets isFocusable, which keyboard navigation also reads, and ReactImageManager had no focusable setter, so the prop did nothing. Image.android.js also never turned tabIndex into focusable the way View does.

ReactImageManager now handles focusable, and ReactImageView leaves itself out of addFocusables and refuses requestFocus when it is false. isFocusable stays tied to accessible, so TalkBack still reaches the image. A focused image stays a candidate so focus can move on from it. Image.android.js maps tabIndex to focusable like View.js. This is the Image side of #59048 (View) and #59139 (Text).

Fixes #60168

Changelog:

[ANDROID] [FIXED] - focusable={false} and tabIndex={-1} take an accessible Image out of hardware-keyboard navigation

Test Plan:

Added testFocusableFalseKeepsAccessibleImageOutOfKeyboardFocus to ReactImagePropertyTest. It sets accessible and focusable={false} through updateProperties, then checks that addFocusables adds nothing, requestFocus fails and isFocusable stays true, and that focusable={true} makes the image a candidate again. It fails on main and passes with the change.

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -Preact.internal.useHermesStable=true

The full ReactAndroid unit test suite passes, and format-check-kotlin, ESLint, Prettier and flow full-check are clean. I didn't run the reproducer on a device.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 20, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 20, 2026
@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

On this PR's head (664c6aa), an <Image accessible={true} focusable={false} /> still stops keyboard focus when another view's nextFocusDown or nextFocusForward names it: D-pad Down or Tab from that view leaves focus where it is instead of moving on.

I built RNTester's release APK (arm64-v8a) from 664c6aa with this component registered as RNTesterApp in packages/rn-tester/js/RNTesterApp.android.js, and ran it on an Android 15 emulator (API 35, sdk_gphone64_x86_64):

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},
});
  1. Tap input, then press Tab: focus moves to source.
  2. Press D-pad Down, D-pad Down again, then Tab.
  3. Tap "unname the image", which drops the image's tag from source's nextFocusDown and nextFocusForward. Tap input, press Tab, then D-pad Down; press D-pad Up, then Tab.

Expected: in step 2 focus moves from source to after, as it does in step 3.

Actual, the focused node in the view tree after each key:

[tab-from-input] focused node: [21,387][1059,503]  1038x116  ViewGroup  #source  desc="source"  clickable  focused
[dpad-down-from-source] focused node: [21,387][1059,503]  1038x116  ViewGroup  #source  desc="source"  clickable  focused
[dpad-down-again] focused node: [21,387][1059,503]  1038x116  ViewGroup  #source  desc="source"  clickable  focused
[tab-from-source] focused node: [21,387][1059,503]  1038x116  ViewGroup  #source  desc="source"  clickable  focused
[unnamed-dpad-down-from-source] focused node: [21,660][1059,776]  1038x116  ViewGroup  #after  desc="after"  clickable  focused
[unnamed-tab-from-source] focused node: [21,660][1059,776]  1038x116  ViewGroup  #after  desc="after"  clickable  focused

FocusFinder.findNextUserSpecifiedFocus returns the named view while its isFocusable() is true, which this PR keeps for an accessible image (testFocusableFalseKeepsAccessibleImageOutOfKeyboardFocus asserts it), and the new requestFocus override then refuses it.

@lazerg

lazerg commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at be25220e47ed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: an accessible Image takes hardware-keyboard focus even with focusable={false} or tabIndex={-1}

2 participants