android-React Native-AccessibilityInfo.setAccessibilityFocus()中的reactTag参数是什么?

什么是AccessibilityInfo.setAccessibilityFocus(reactTag)方法中的reactTag参数? React native documentation不提供有关此参数的任何信息:

Set accessibility focus to a React component. On Android, this is equivalent
to UIManager.sendAccessibilityEvent(reactTag,
UIManager.AccessibilityEventTypes.typeViewFocused);.

我没有Objective-C和Java的背景.一个小例子将不胜感激.谢谢 !!!

解决方法:

reactTag只是React用来标识应用程序中的视图对象的数字.它是findNodeHandle函数的结果,该函数将视图引用作为参数.

这是一个有关如何使用它的简单示例:

import React, {Component} from 'react'
import {
  ...
  findNodeHandle,
  ...
} from 'react-native';

class Sample extends React.Component {
    constructor(props) {
        super(props)
        this.viewRef = null;
    }

    ...

    componentDidMount() {
        if (this.viewRef) {
            const reactTag = findNodeHandle(this.viewRef);
            AccessibilityInfo.setAccessibilityFocus(reactTag);
        }
    }

    render() {
        return (
            <View ref={el => { this.viewRef = el }}>
                ...
            </View>
        )
    }
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...