What is reactTag
parameter in AccessibilityInfo.setAccessibilityFocus(reactTag)
method? React native documentation don't provide any information about this parameter:
Set accessibility focus to a React component. On Android, this is equivalent to UIManager.sendAccessibilityEvent(reactTag, UIManager.AccessibilityEventTypes.typeViewFocused);.
I don't have any background of Objective-C
and Java
. A little example will be more appreciated. Thank !!!
reactTag is simply a number that is used by react to identify view objects in your application. It is the result of findNodeHandle function, which takes a view reference as parameter.
onMagicTap In the Phone app on iPhone, a magic tap answers a phone call, or ends the current one. If the selected element does not have an onMagicTap function, the system will traverse up the view hierarchy until it finds a view that does.
On Android, you can use Accessibility Scanner. To use it with an emulator, download the Accessibility Inspector APKand then drag-and-drop to your emulator.
reactTag
is simply a number that is used by react to identify view objects in your application. It is the result of findNodeHandle
function, which takes a view reference as parameter.
Here's a simple example on how you can use it:
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>
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With