react-native-security-suite 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/securitysuite/SecureFragment.java +25 -4
- package/android/src/main/java/com/securitysuite/SecureView.java +58 -2
- package/android/src/main/java/com/securitysuite/SecureViewManager.java +31 -35
- package/android/src/main/java/com/securitysuite/SecuritySuitePackage.java +0 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.securitysuite;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
4
5
|
import android.os.Bundle;
|
|
5
6
|
import android.util.Log;
|
|
6
7
|
import android.view.LayoutInflater;
|
|
@@ -9,6 +10,7 @@ import android.view.ViewGroup;
|
|
|
9
10
|
import android.view.Window;
|
|
10
11
|
import android.view.WindowManager;
|
|
11
12
|
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
12
14
|
import androidx.fragment.app.Fragment;
|
|
13
15
|
|
|
14
16
|
public class SecureFragment extends Fragment {
|
|
@@ -21,17 +23,35 @@ public class SecureFragment extends Fragment {
|
|
|
21
23
|
return secureView;
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
@Override
|
|
27
|
+
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
28
|
+
super.onCreate(savedInstanceState);
|
|
29
|
+
Log.d("SecureFragment", "onCreate");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
public void onAttach(Context context) {
|
|
34
|
+
super.onAttach(context);
|
|
35
|
+
Log.d("SecureFragment", "onAttach");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Override
|
|
39
|
+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
40
|
+
super.onActivityCreated(savedInstanceState);
|
|
41
|
+
Log.d("SecureFragment", "onActivityCreated");
|
|
42
|
+
}
|
|
43
|
+
|
|
24
44
|
@Override
|
|
25
45
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
26
46
|
super.onViewCreated(view, savedInstanceState);
|
|
27
|
-
Log.d("
|
|
47
|
+
Log.d("SecureFragment", "onViewCreated");
|
|
28
48
|
final Activity activity = getActivity();
|
|
29
49
|
if (activity != null) {
|
|
30
50
|
activity.runOnUiThread(new Runnable() {
|
|
31
51
|
@Override
|
|
32
52
|
public void run() {
|
|
33
53
|
Window window = activity.getWindow();
|
|
34
|
-
|
|
54
|
+
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
35
55
|
}
|
|
36
56
|
});
|
|
37
57
|
}
|
|
@@ -40,18 +60,19 @@ public class SecureFragment extends Fragment {
|
|
|
40
60
|
@Override
|
|
41
61
|
public void onPause() {
|
|
42
62
|
super.onPause();
|
|
63
|
+
Log.d("SecureFragment", "onPause");
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
@Override
|
|
46
67
|
public void onResume() {
|
|
47
68
|
super.onResume();
|
|
69
|
+
Log.d("SecureFragment", "onResume");
|
|
48
70
|
}
|
|
49
71
|
|
|
50
72
|
@Override
|
|
51
73
|
public void onDestroy() {
|
|
52
74
|
super.onDestroy();
|
|
53
|
-
|
|
54
|
-
Log.d("hereeeee", "2");
|
|
75
|
+
Log.d("SecureFragment", "onDestroy");
|
|
55
76
|
final Activity activity = getActivity();
|
|
56
77
|
if (activity != null) {
|
|
57
78
|
activity.runOnUiThread(new Runnable() {
|
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
package com.securitysuite;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
|
+
import android.view.View;
|
|
4
5
|
import android.widget.FrameLayout;
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
8
|
+
import com.facebook.react.uimanager.UIManagerModule;
|
|
6
9
|
|
|
7
10
|
public class SecureView extends FrameLayout {
|
|
8
|
-
|
|
11
|
+
private View contentView;
|
|
12
|
+
|
|
13
|
+
public SecureView(Context context) {
|
|
9
14
|
super(context);
|
|
10
15
|
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public void requestLayout() {
|
|
19
|
+
super.requestLayout();
|
|
20
|
+
post(measureAndLayout);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private final Runnable measureAndLayout = () -> {
|
|
24
|
+
measure(
|
|
25
|
+
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
|
|
26
|
+
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
|
|
27
|
+
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
@Override
|
|
31
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
32
|
+
int maxWidth = 0;
|
|
33
|
+
int maxHeight = 0;
|
|
34
|
+
|
|
35
|
+
for (int i = 0; i < getChildCount(); i++) {
|
|
36
|
+
View child = getChildAt(i);
|
|
37
|
+
if (child.getVisibility() != GONE) {
|
|
38
|
+
child.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
|
|
39
|
+
|
|
40
|
+
maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
|
|
41
|
+
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
int finalWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
|
|
46
|
+
int finalHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
|
|
47
|
+
|
|
48
|
+
setMeasuredDimension(finalWidth, finalHeight);
|
|
49
|
+
|
|
50
|
+
ThemedReactContext reactContext = (ThemedReactContext) getContext();
|
|
51
|
+
UIManagerModule uiManagerModule = reactContext.getNativeModule(UIManagerModule.class);
|
|
52
|
+
|
|
53
|
+
if (uiManagerModule != null) {
|
|
54
|
+
reactContext.runOnNativeModulesQueueThread(() -> uiManagerModule.updateNodeSize(getId(), finalWidth, finalHeight));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
public void setContentView(View view) {
|
|
60
|
+
contentView = view;
|
|
61
|
+
addView(contentView);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public View getContentView() {
|
|
65
|
+
return contentView;
|
|
66
|
+
}
|
|
11
67
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
package com.securitysuite;
|
|
2
2
|
|
|
3
|
+
import android.app.Activity;
|
|
3
4
|
import android.view.Choreographer;
|
|
4
5
|
import android.view.View;
|
|
5
6
|
import android.view.ViewGroup;
|
|
7
|
+
import android.view.Window;
|
|
8
|
+
import android.view.WindowManager;
|
|
6
9
|
import android.widget.FrameLayout;
|
|
7
10
|
|
|
8
11
|
import androidx.annotation.NonNull;
|
|
@@ -18,7 +21,7 @@ import com.facebook.react.uimanager.ThemedReactContext;
|
|
|
18
21
|
|
|
19
22
|
import java.util.Map;
|
|
20
23
|
|
|
21
|
-
public class SecureViewManager extends ViewGroupManager<
|
|
24
|
+
public class SecureViewManager extends ViewGroupManager<SecureView> {
|
|
22
25
|
|
|
23
26
|
public static final String REACT_CLASS = "SecureView";
|
|
24
27
|
public final int COMMAND_CREATE = 1;
|
|
@@ -36,33 +39,33 @@ public class SecureViewManager extends ViewGroupManager<FrameLayout> {
|
|
|
36
39
|
return REACT_CLASS;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
/**
|
|
40
|
-
* Return a FrameLayout which will later hold the Fragment
|
|
41
|
-
*/
|
|
42
42
|
@Override
|
|
43
|
-
public
|
|
44
|
-
|
|
43
|
+
public SecureView createViewInstance(ThemedReactContext reactContext) {
|
|
44
|
+
// TODO: move this to the fragment lifycycle
|
|
45
|
+
final Activity activity = reactContext.getCurrentActivity();
|
|
46
|
+
if (activity != null) {
|
|
47
|
+
activity.runOnUiThread(new Runnable() {
|
|
48
|
+
@Override
|
|
49
|
+
public void run() {
|
|
50
|
+
Window window = activity.getWindow();
|
|
51
|
+
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return new SecureView(reactContext);
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
/**
|
|
48
|
-
* Map the "create" command to an integer
|
|
49
|
-
*/
|
|
50
58
|
@Nullable
|
|
51
59
|
@Override
|
|
52
60
|
public Map<String, Integer> getCommandsMap() {
|
|
53
61
|
return MapBuilder.of("create", COMMAND_CREATE);
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
/**
|
|
57
|
-
* Handle "create" command (called from JS) and call createFragment method
|
|
58
|
-
*/
|
|
59
|
-
@Override
|
|
60
64
|
public void receiveCommand(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
super.receiveCommand(root, commandId, args);
|
|
65
|
+
@NonNull FrameLayout root,
|
|
66
|
+
String commandId,
|
|
67
|
+
@Nullable ReadableArray args) {
|
|
68
|
+
super.receiveCommand((SecureView) root, commandId, args);
|
|
66
69
|
int reactNativeViewId = args.getInt(0);
|
|
67
70
|
int commandIdInt = Integer.parseInt(commandId);
|
|
68
71
|
|
|
@@ -70,11 +73,12 @@ public class SecureViewManager extends ViewGroupManager<FrameLayout> {
|
|
|
70
73
|
case COMMAND_CREATE:
|
|
71
74
|
createFragment(root, reactNativeViewId);
|
|
72
75
|
break;
|
|
73
|
-
default: {
|
|
76
|
+
default: {
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
@ReactPropGroup(names = {"width", "height"}, customType = "Style")
|
|
81
|
+
@ReactPropGroup(names = { "width", "height" }, customType = "Style")
|
|
78
82
|
public void setStyle(FrameLayout view, int index, Integer value) {
|
|
79
83
|
if (index == 0) {
|
|
80
84
|
propWidth = value == -1 ? ViewGroup.LayoutParams.MATCH_PARENT : value;
|
|
@@ -85,9 +89,6 @@ public class SecureViewManager extends ViewGroupManager<FrameLayout> {
|
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
/**
|
|
89
|
-
* Replace your React Native view with a custom fragment
|
|
90
|
-
*/
|
|
91
92
|
public void createFragment(FrameLayout root, int reactNativeViewId) {
|
|
92
93
|
ViewGroup parentView = (ViewGroup) root.findViewById(reactNativeViewId);
|
|
93
94
|
setupLayout(parentView);
|
|
@@ -95,9 +96,9 @@ public class SecureViewManager extends ViewGroupManager<FrameLayout> {
|
|
|
95
96
|
final SecureFragment myFragment = new SecureFragment();
|
|
96
97
|
FragmentActivity activity = (FragmentActivity) reactContext.getCurrentActivity();
|
|
97
98
|
activity.getSupportFragmentManager()
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
.beginTransaction()
|
|
100
|
+
.replace(reactNativeViewId, myFragment, String.valueOf(reactNativeViewId))
|
|
101
|
+
.commit();
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
public void setupLayout(View view) {
|
|
@@ -111,18 +112,13 @@ public class SecureViewManager extends ViewGroupManager<FrameLayout> {
|
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
/**
|
|
115
|
-
* Layout all children properly
|
|
116
|
-
*/
|
|
117
115
|
public void manuallyLayoutChildren(View view) {
|
|
118
|
-
int width = propWidth == ViewGroup.LayoutParams.MATCH_PARENT ?
|
|
119
|
-
|
|
120
|
-
int height = propHeight == ViewGroup.LayoutParams.MATCH_PARENT ?
|
|
121
|
-
ViewGroup.LayoutParams.MATCH_PARENT : propHeight;
|
|
116
|
+
int width = propWidth == ViewGroup.LayoutParams.MATCH_PARENT ? ViewGroup.LayoutParams.MATCH_PARENT : propWidth;
|
|
117
|
+
int height = propHeight == ViewGroup.LayoutParams.MATCH_PARENT ? ViewGroup.LayoutParams.MATCH_PARENT : propHeight;
|
|
122
118
|
|
|
123
119
|
view.measure(
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
121
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
|
|
126
122
|
|
|
127
123
|
view.layout(0, 0, width, height);
|
|
128
124
|
}
|
|
@@ -6,7 +6,6 @@ import com.facebook.react.bridge.NativeModule;
|
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
7
|
import com.facebook.react.uimanager.ViewManager;
|
|
8
8
|
import java.util.ArrayList;
|
|
9
|
-
import java.util.Collections;
|
|
10
9
|
import java.util.List;
|
|
11
10
|
|
|
12
11
|
public class SecuritySuitePackage implements ReactPackage {
|