Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into publish/0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Aug 2, 2024
2 parents 5986091 + e96fa52 commit a706753
Show file tree
Hide file tree
Showing 316 changed files with 17,134 additions and 3,648 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.debank.rabbymobile;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.app.Activity;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -32,7 +31,6 @@ public class RNScreenshotPreventModule extends EventEmitterPackageSpec implement
public static final String NAME = "RNScreenshotPrevent";
private final ReactApplicationContext reactContext;
private RelativeLayout overlayLayout;
private boolean secureFlagWasSet;

public RNScreenshotPreventModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -47,11 +45,21 @@ public String getName() {
return NAME;
}

private static void setSecure(Activity activity) {
private static ViewGroup activityGetRootView(Activity activity) {
ViewGroup rootView = (ViewGroup) activity.getWindow().getDecorView().getRootView();
return rootView;
}

private static boolean activityIsSecure(Activity activity) {
int flags = activity.getWindow().getAttributes().flags;
return (flags & WindowManager.LayoutParams.FLAG_SECURE) != 0;
}

private static void activitySetSecure(Activity activity) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}

private static void cancelSecure(Activity activity) {
private static void activityCancelSecure(Activity activity) {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}

Expand All @@ -68,22 +76,22 @@ public void togglePreventScreenshot(boolean isPrevent) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
RNScreenshotPreventModule.setSecure(activity);
activitySetSecure(activity);
}
});
} else {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
RNScreenshotPreventModule.cancelSecure(activity);
activityCancelSecure(activity);
}
});
}
params.putBoolean("success", true);
}
}

this.rnSendEvent(reactContext, "preventScreenshotChanged", params);
RabbyUtils.rnCtxSendEvent(reactContext, "preventScreenshotChanged", params);
}

@ReactMethod
Expand Down Expand Up @@ -115,7 +123,7 @@ public boolean iosIsBeingCaptured() {

private void createOverlay(Activity activity, String imagePath) {
overlayLayout = new RelativeLayout(activity);
overlayLayout.setBackgroundColor(Color.parseColor("#FFFFFF"));
overlayLayout.setBackgroundColor(Color.parseColor("#7084FF"));

// Create an ImageView
ImageView imageView = new ImageView(activity);
Expand All @@ -141,44 +149,43 @@ private void createOverlay(Activity activity, String imagePath) {
@Override
public void onHostResume() {
Activity currentActivity = this.reactContext.getCurrentActivity();
if (currentActivity != null && overlayLayout != null) {
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewGroup rootView = (ViewGroup) currentActivity.getWindow().getDecorView().getRootView();
rootView.removeView(overlayLayout);
if (secureFlagWasSet) {
currentActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
secureFlagWasSet = false;
}
}
});
}
WritableMap params = Arguments.createMap();
params.putString("state", "resume");
RabbyUtils.rnCtxSendEvent(reactContext, "androidOnLifeCycleChanged", params);
// if (currentActivity != null && overlayLayout != null) {
// currentActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (overlayLayout != null) {
// activityGetRootView(currentActivity).removeView(overlayLayout);
// overlayLayout = null;
// }
// }
// });
// }
}

@Override
public void onHostPause() {
Activity currentActivity = this.reactContext.getCurrentActivity();
if (currentActivity != null && overlayLayout != null) {
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewGroup rootView = (ViewGroup) currentActivity.getWindow().getDecorView().getRootView();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
rootView.addView(overlayLayout, layoutParams);

int flags = currentActivity.getWindow().getAttributes().flags;
if ((flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
currentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
secureFlagWasSet = true;
} else {
secureFlagWasSet = false;
}
}
});
}
WritableMap params = Arguments.createMap();
params.putString("state", "pause");
RabbyUtils.rnCtxSendEvent(reactContext, "androidOnLifeCycleChanged", params);

// if (currentActivity != null && overlayLayout == null) {
// currentActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// ViewGroup rootView = activityGetRootView(currentActivity);
// createOverlay(currentActivity, "");

// RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT);
// rootView.addView(overlayLayout, layoutParams);
// }
// });
// }
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.debank.rabbymobile;

import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class RabbyUtils {
static protected void rnCtxSendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.debank.rabbymobile;

import androidx.annotation.Nullable;

import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;

abstract class EventEmitterPackageSpec extends ReactContextBaseJavaModule {
EventEmitterPackageSpec(ReactApplicationContext context) {
super(context);
}

protected void rnSendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
// private static final List<EventDispatcherListener> mListeners = new CopyOnWriteArrayList<>();

private int listenerCount = 0;
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/ios/RabbyMobile/RNScreenshotPrevent.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ @implementation RNScreenshotPrevent {
return @[
@"userDidTakeScreenshot",
@"screenCapturedChanged",
@"preventScreenshotChanged"
@"preventScreenshotChanged",
@"androidOnLifeCycleChanged" // robust, not really used
];
}

Expand Down
35 changes: 18 additions & 17 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,37 @@
},
"scripts": {
"android": "react-native run-android",
"apply-patch": "patch-package",
"build-inpage": "sh ./scripts/postinstall.sh",
"build:deps": "yarn ../../ build",
"create-patch": "sh ./scripts/create-patch.sh",
"devtools": "react-devtools",
"doctor": "react-native doctor",
"ensure-git-hooks": "yarn ../../ install-husky",
"postinstall": "yarn build:deps && yarn build-inpage && patch-package",
"ios": "react-native run-ios",
"lint:commit:fix": "eslint ./src --quiet --fix --ext .js,.jsx,.ts,.tsx --max-warnings=-1",
"link-assets": "react-native-asset",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
"lint:commit:fix": "eslint ./src --quiet --fix --ext .js,.jsx,.ts,.tsx --max-warnings=-1",
"lint:fix": "eslint ./src --fix --ext .js,.jsx,.ts,.tsx",
"prepare-archive": "yarn build:deps && yarn build-inpage",
"restart": "yarn start --reset-cache",
"build:deps": "yarn ../../ build",
"start": "yarn ensure-git-hooks && yarn build:deps && yarn build-inpage && react-native start",
"sync:data": "node ./scripts/sync.js",
"ensure-git-hooks": "yarn ../../ install-husky",
"syncrnversion:incb": "./node_modules/.bin/react-native-version --never-amend",
"syncrnversion": "./node_modules/.bin/react-native-version --never-amend --never-increment-build",
"start": "yarn ensure-git-hooks && yarn build:deps && yarn build-inpage && react-native start",
"prepare-archive": "yarn build:deps && yarn build-inpage",
"syncrnversion:incb": "./node_modules/.bin/react-native-version --never-amend",
"test": "jest",
"build-inpage": "sh ./scripts/postinstall.sh",
"create-patch": "sh ./scripts/create-patch.sh",
"apply-patch": "patch-package",
"link-assets": "react-native-asset",
"postinstall": "yarn build:deps && yarn build-inpage && patch-package",
"postversion": "react-native-version --never-amend"
},
"lint-staged": {
"*.{,js,jsx,ts,tsx}": "eslint --fix --quiet",
"*": "prettier --write --ignore-unknown"
},
"resolutions": {
"eth-rpc-errors": "^4.0.3",
"json-rpc-engine/eth-rpc-errors": "^4.0.3",
"readable-stream": "3.6.2"
},
"dependencies": {
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@debank/common": "0.3.58",
Expand All @@ -60,7 +65,7 @@
"@rabby-wallet/gnosis-sdk": "^1.3.6",
"@rabby-wallet/object-multiplex": "workspace:^",
"@rabby-wallet/persist-store": "workspace:^",
"@rabby-wallet/rabby-api": "0.7.23-beta.1",
"@rabby-wallet/rabby-api": "0.7.24",
"@rabby-wallet/rabby-security-engine": "2.0.4",
"@rabby-wallet/rabby-swap": "0.0.38-beta.1",
"@rabby-wallet/service-address": "workspace:^",
Expand Down Expand Up @@ -163,6 +168,7 @@
"semver": "^7.5.4",
"styled-components": "^6.1.1",
"use-count-up": "^3.0.1",
"viem": "^2.17.4",
"web3": "^4.3.0",
"web3-eth-abi": "1.7.0",
"web3-utils": "1.7.0",
Expand Down Expand Up @@ -212,11 +218,6 @@
"ts-toolbelt": "^9.6.0",
"typescript": "4.8.4"
},
"resolutions": {
"eth-rpc-errors": "^4.0.3",
"json-rpc-engine/eth-rpc-errors": "^4.0.3",
"readable-stream": "3.6.2"
},
"engines": {
"node": ">=16.0.0"
},
Expand Down
Loading

0 comments on commit a706753

Please sign in to comment.