diff --git a/package.json b/package.json index 0fbe6d0..a10db0e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "react-native-screenshot-prevent", - "version": "1.1.4", + "version": "1.1.5", "description": "This fork contains fully working blank screenshot on IOS13+ including screen recording", "main": "lib/commonjs/index", "module": "lib/module/index", - "types": "index.d.ts", + "types": "./src/index.d.ts", "react-native": "index", "source": "./src/index", "files": [ @@ -28,6 +28,7 @@ "scripts": { "test": "jest", "typecheck": "tsc --noEmit", + "prepare": "bob build", "lint": "eslint \"**/*.{js,ts,tsx}\"" }, "keywords": [ @@ -43,6 +44,7 @@ }, "homepage": "https://github.com/killserver/react-native-screenshot-prevent#readme", "devDependencies": { + "@react-native-community/bob": "^0.4.1", "@commitlint/config-conventional": "^17.0.2", "@evilmartians/lefthook": "^1.2.2", "@react-native-community/eslint-config": "^3.0.2", @@ -113,6 +115,14 @@ "trailingComma": "es5", "useTabs": true }, + "@react-native-community/bob": { + "source": "src", + "output": "lib", + "targets": [ + "module", + "typescript" + ] + }, "codegenConfig": { "name": "RNScreenshotPreventSpec", "type": "modules", diff --git a/src/index.d.ts b/src/index.d.ts index 0f14734..e14d3a2 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -4,5 +4,5 @@ declare module 'react-native-screenshot-prevent' { export function disableSecureView(): void; export function usePreventScreenshot(): void; export function useDisableSecureView(): void; - export function addListener(fn: Function) => void; + export function addListener(fn: Function): void; } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 03036d4..987821b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,12 @@ import { NativeModules, NativeEventEmitter, Platform } from 'react-native'; import { useEffect } from 'react'; -let addListen, RNScreenshotPrevent; +type FN = (resp: any) => void +type Return = { + readonly remove: () => void +} + +let addListen: any, RNScreenshotPrevent: any; if(Platform.OS !== "web") { const { RNScreenshotPrevent: RNScreenshotPreventNative } = NativeModules; RNScreenshotPrevent = RNScreenshotPreventNative @@ -12,7 +17,7 @@ if(Platform.OS !== "web") { * @param {function} callback handler * @returns {function} unsubscribe fn */ - addListen = (fn): void => { + addListen = (fn: FN): Return => { if(typeof(fn) !== 'function') { console.error('RNScreenshotPrevent: addListener requires valid callback function'); return { @@ -27,7 +32,7 @@ if(Platform.OS !== "web") { } else { RNScreenshotPrevent = { enabled: (enabled: boolean): void => { - console.warn("RNScreenshotPrevent: enabled not work in web"); + console.warn("RNScreenshotPrevent: enabled not work in web. value: "+enabled); }, enableSecureView: (): void => { console.warn("RNScreenshotPrevent: enableSecureView not work in web"); @@ -36,7 +41,7 @@ if(Platform.OS !== "web") { console.warn("RNScreenshotPrevent: disableSecureView not work in web"); } } - addListen = (fn): void => { + addListen = (fn: FN): Return => { if(typeof(fn) !== 'function') { console.error('RNScreenshotPrevent: addListener requires valid callback function'); return { @@ -72,5 +77,8 @@ export const useDisableSecureView = () => { }, []); } -export const addListener = addListen +export const enabled: (enabled: boolean) => void = RNScreenshotPrevent.enabled +export const enableSecureView: () => void = RNScreenshotPrevent.enableSecureView +export const disableSecureView: () => void = RNScreenshotPrevent.disableSecureView +export const addListener: (fn: FN) => void = addListen export default RNScreenshotPrevent; diff --git a/tsconfig.json b/tsconfig.json index 0e1c849..176e012 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,8 +4,6 @@ "paths": { "react-native-screenshot-prevent": ["./src/index"] }, - "files": ["src/index.d.ts"], - "include": ["src/index.ts"], "allowUnreachableCode": false, "allowUnusedLabels": false, "esModuleInterop": true,