react-native-cbm-screen-shot
v1.0.5
Published
## Getting started
Downloads
6
Readme
react-native-cbm-screen-shot
Getting started
$ npm install react-native-cbm-screen-shot --save
Mostly automatic installation
$ react-native link react-native-cbm-screen-shot
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-cbm-screen-shot
and addRNCbmScreenShot.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNCbmScreenShot.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.reactlibrary.RNCbmScreenShotPackage;
to the imports at the top of the file - Add
new RNCbmScreenShotPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-cbm-screen-shot' project(':react-native-cbm-screen-shot').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cbm-screen-shot/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-cbm-screen-shot')
Usage
// In android, it module needs to be registered in onCreated
# mainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
....
RNCbmScreenShotModule.initScreenShotShareSDK(this);
....
}
import RNCbmScreenShot, {addScreenShotListener, removeScreenShotListener} from 'react-native-cbm-screen-shot';
useEffect(async ()=>{
if (Platform.OS === 'android') {
// In Android, READ_EXTERNAL_STORAGE permission is required
const granted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
if (!granted) return
}
addScreenShotListener((data)=>{
// When the system takes a screenshot, it will listen here and return the image address of the screenshot
console.log(data.uri)
})
return async ()=>{
if (Platform.OS === 'android') {
// In Android, READ_EXTERNAL_STORAGE permission is required
const granted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
if (!granted) return
}
removeScreenShotListener()
}
},[])