Skip to content

detect system screenshot events and get the image uri by react native

Notifications You must be signed in to change notification settings

krmao/react-native-screenshot-url

 
 

Repository files navigation

react-native-screenshot-url

npm version

Install

yarn add react-native-screenshot-url

Usage

import ScreenShotUtil, { CallbackInfo } from 'react-native-screenshot-url';

const [screenShotUri, setScreenShotUri] = useState<string | undefined>(undefined);


useEffect(() => {
    ScreenShotUtil.startListener((res: CallbackInfo) => {
        console.log('- [Start] screenShot callback res.code=', res.code);
        if (res.code === '200') {
            setScreenShotUri(res.uri);

            //region 5s消失术
            if (timeoutIdRef.current) {
                clearTimeout(timeoutIdRef.current);
            }
            console.log('- [Start] screenShot 5s wait start');
            timeoutIdRef.current = setTimeout(() => {
                console.log('- [Start] screenShot 5s wait end');
                setScreenShotUri(undefined);
            }, 5000);
            //endregion
        } else if (res.code === '198') {
            console.log('- [Start] screenShot callback 198 show permission description');
            showDescription('AAAAA', 'BBBBBO', 'mediaPermission');
        } else if (res.code === '199') {
            console.log('- [Start] screenShot callback 199 hide permission description');
            PermissionUtil.hideDescriptionWithDialogName('mediaPermission');
        }
    }, '截屏,screen');

    return () => {
        ScreenShotUtil.stopListener();
    };
});

Features

  • support 22 - 32 permissions about images READ_EXTERNAL_STORAGE
  • support Android API level 33 permissions about images READ_MEDIA_IMAGES
  • startListener without permission
  • permission request is built-in before callback

Reference

About

detect system screenshot events and get the image uri by react native

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 56.0%
  • Objective-C 33.8%
  • JavaScript 9.3%
  • Ruby 0.9%