react-native-accessible-image
v1.0.0
Published
A React Native image component which supports accessibility focus events
Downloads
1
Maintainers
Readme
react-native-accessible-image
React Native's Accessibility APIs doesn't provide a method to listen for focus enter on a certain view. React Native Accessibility Focus provides an alternative Image component, which is able to listen for accessibility events like accessibility-focus-start
and accessibility-focus-end
.
Getting started
$ npm install react-native-accessible-image --save
Mostly automatic installation
$ react-native link react-native-accessible-image
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-accessible-image
and addRNAccessibilityFocus.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNAccessibilityFocus.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.thetwo.accessibilityfocus.RNAccessibilityFocusPackage;
to the imports at the top of the file - Add
new RNAccessibilityFocusPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-accessible-image' project(':react-native-accessible-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-accessible-image/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-accessible-image')
Usage
import AccessibleImage from 'react-native-accessible-image';
<AccessibleImage
src={require('./my-image-path.png')}
style={{ flex: 1 }}
onFocusStart={() => console.log('focus started')}
onFocusEnd={() => console.log('focus end')}
onPress={() => console.log('pressed')}
onLongPress={() => console.log('long pressed')}
/>