Skip to content

Commit

Permalink
release: v1.9.6 (#37)
Browse files Browse the repository at this point in the history
[fix: reactContext.getCurrentActivity is sometime return
null](c5a7a55)
  • Loading branch information
wn-na authored Mar 20, 2024
2 parents 121e576 + 299588f commit f32ff36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private Method getScreenCaptureCallback() {
if (Build.VERSION.SDK_INT < 34) {
return null;
}
return Utils.getMethod(reactContext.getCurrentActivity().getClass(), "registerScreenCaptureCallback");
return Utils.getMethod(getCurrentActivity().getClass(), "registerScreenCaptureCallback");
}

public void createCaptureCallback() {
Expand Down Expand Up @@ -169,7 +169,7 @@ public void onHostResume() {
createCaptureCallback();
}
registerScreenCaptureCallback.invoke(
reactContext.getCurrentActivity(),
getCurrentActivity(),
Utils.MainExecutor.INSTANCE,
(Object) screenCaptureCallback);
}
Expand All @@ -187,10 +187,10 @@ public void onHostDestroy() {
try {
if (Build.VERSION.SDK_INT >= 34) {
Method method = Utils.getMethod(
reactContext.getCurrentActivity().getClass(),
getCurrentActivity().getClass(),
"unregisterScreenCaptureCallback");
if (method != null && screenCaptureCallback != null) {
method.invoke(reactContext.getCurrentActivity(), (Object) screenCaptureCallback);
method.invoke(getCurrentActivity(), (Object) screenCaptureCallback);
}
}
} catch (Exception e) {
Expand All @@ -212,13 +212,13 @@ private boolean requestStoragePermission() {
? "android.permission.READ_MEDIA_IMAGES" // Manifest.permission.READ_MEDIA_IMAGES
: Manifest.permission.READ_EXTERNAL_STORAGE;

if (ContextCompat.checkSelfPermission(reactContext.getCurrentActivity(),
if (ContextCompat.checkSelfPermission(getCurrentActivity(),
requestPermission) == PackageManager.PERMISSION_GRANTED) {
Log.d(NAME, "Permission is granted");
return true;
} else {
Log.d(NAME, "Permission is revoked");
ActivityCompat.requestPermissions(reactContext.getCurrentActivity(), new String[] { requestPermission }, 1);
ActivityCompat.requestPermissions(getCurrentActivity(), new String[] { requestPermission }, 1);
return false;
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ private void removeListener() {
}

private boolean isSecureFlag() {
return (reactContext.getCurrentActivity().getWindow().getAttributes().flags
return (getCurrentActivity().getWindow().getAttributes().flags
& WindowManager.LayoutParams.FLAG_SECURE) != 0;
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public void isScreenRecording(Promise promise) {
public void preventScreenshot(Promise promise) {
runOnUiThread(() -> {
try {
reactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, true, true,
CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal());
Expand All @@ -364,7 +364,7 @@ public void preventScreenshot(Promise promise) {
public void allowScreenshot(Boolean removeListener, Promise promise) {
runOnUiThread(() -> {
try {
reactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);

sendEvent(CaptureProtectionConstant.LISTENER_EVENT_NAME, false, false,
CaptureProtectionConstant.CaptureProtectionModuleStatus.UNKNOWN.ordinal());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-capture-protection",
"version": "1.9.5",
"version": "1.9.6",
"description": "It’s a library for React Native to control simple capture events(i.e. Screenshot or Screen record)",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit f32ff36

Please sign in to comment.