1.0.5 • Published 2 years ago

react-native-cbm-screen-shot v1.0.5

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

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

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-cbm-screen-shot and add RNCbmScreenShot.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNCbmScreenShot.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. 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 the getPackages() method
  1. 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')
  2. 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()
	}
},[])
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago