Skip to content

Commit c194210

Browse files
authored
Merge pull request #12 from andy6shen/dev
修复自定义视图无法点击的问题;修复安卓自定义视图不显示的问题
2 parents 5528d69 + 9a55dec commit c194210

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

android/src/main/java/cn/jiguang/plugins/verification/JVerificationModule.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package cn.jiguang.plugins.verification;
22

3-
import android.app.Application;
43
import android.text.TextUtils;
54
import android.widget.ImageView;
65
import android.widget.RelativeLayout;
76

8-
import com.facebook.react.ReactInstanceManager;
7+
import com.facebook.react.ReactApplication;
98
import com.facebook.react.ReactRootView;
109
import com.facebook.react.bridge.Arguments;
1110
import com.facebook.react.bridge.Callback;
@@ -15,9 +14,7 @@
1514
import com.facebook.react.bridge.ReadableArray;
1615
import com.facebook.react.bridge.ReadableMap;
1716
import com.facebook.react.bridge.WritableMap;
18-
import com.facebook.react.common.LifecycleState;
1917
import com.facebook.react.modules.core.DeviceEventManagerModule;
20-
import com.facebook.react.shell.MainReactPackage;
2118

2219
import java.lang.reflect.Field;
2320

@@ -403,16 +400,8 @@ private ReactRootView convertToView(ReadableMap readableMap){
403400
return null;
404401
}
405402
ReactRootView reactView = new ReactRootView(reactContext);
406-
ReactInstanceManager reactInstanceManager = ReactInstanceManager.builder()
407-
.setApplication((Application) reactContext.getApplicationContext())
408-
.setCurrentActivity(getCurrentActivity())
409-
.setBundleAssetName("index.android.bundle")
410-
.setJSMainModulePath("index")
411-
.addPackage(new MainReactPackage())
412-
.setUseDeveloperSupport(true)
413-
.setInitialLifecycleState(LifecycleState.RESUMED)
414-
.build();
415-
reactView.startReactApplication(reactInstanceManager, viewName, null);
403+
ReactApplication application = (ReactApplication)getCurrentActivity().getApplication();
404+
reactView.startReactApplication(application.getReactNativeHost().getReactInstanceManager(), viewName);
416405
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
417406
if (viewPoint != null) {
418407
int marginLeft = dp2Pix(viewPoint.getInt(0));

example/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ const customConfigParams = {
141141
};
142142

143143
const customViewParams = [
144-
{customViewName: 'customView1', customViewPoint: [20, 200]},
145-
{customViewName: 'customView2', customViewPoint: [20, 300]},
146-
{customViewName: 'customView3', customViewPoint: [20, 400]},
144+
{customViewName: 'customView1', customViewPoint: [20, 200, 150, 30]},
145+
{customViewName: 'customView2', customViewPoint: [20, 300, 150, 30]},
146+
{customViewName: 'customView3', customViewPoint: [20, 400, 150, 30]},
147147
];
148148

149149
export default class App extends React.Component {

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:label="@string/app_name"
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:theme="@style/AppTheme"
12+
android:networkSecurityConfig="@xml/network_security_config"
1213
tools:ignore="GoogleAppIndexingWarning">
1314
<activity
1415
android:name=".MainActivity"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<base-config cleartextTrafficPermitted="true">
4+
<trust-anchors>
5+
<certificates src="system" />
6+
</trust-anchors>
7+
</base-config>
8+
</network-security-config>

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export default class JVerification {
122122
if (Platform.OS == 'android') {
123123
JVerificationModule.dismissLoginAuthActivity();
124124
}
125+
else {
126+
JVerificationModule.dismissLoginController();
127+
}
125128
}
126129

127130
/**

ios/RCTJVerificationModule/RCTJVerificationModule.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,26 @@ + (BOOL)requiresMainQueueSetup
196196
dispatch_async(dispatch_get_main_queue(), ^{
197197
[JVERIFICATIONService customUIWithConfig:config customViews:^(UIView *customAreaView) {
198198
for (int i = 0; i < viewParams.count; i++) {
199-
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
200-
RCTRootView *rctView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:viewParams[i][CUSTOM_VIEW_NAME] initialProperties:nil launchOptions:nil];
199+
RCTRootView *rctView;
200+
if (self.bridge) {
201+
rctView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:viewParams[i][CUSTOM_VIEW_NAME] initialProperties:nil];
202+
}
203+
else {
204+
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
205+
rctView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:viewParams[i][CUSTOM_VIEW_NAME] initialProperties:nil launchOptions:nil];
206+
}
201207
NSArray *point = viewParams[i][CUSTOM_VIEW_POINT];
202208
NSNumber *pointX = point[0];
203209
NSNumber *pointY = point[1];
210+
NSNumber *pointW = point[2];
211+
NSNumber *pointH = point[3];
204212
CGFloat x = [pointX doubleValue];
205213
CGFloat y = [pointY doubleValue];
214+
CGFloat w = [pointW doubleValue];
215+
CGFloat h = [pointH doubleValue];
206216
CGRect customFrame = rctView.frame;
207217
customFrame.origin = CGPointMake(x, y);
218+
customFrame.size = CGSizeMake(w, h);
208219
rctView.frame = customFrame;
209220
[customAreaView addSubview:rctView];
210221
}

0 commit comments

Comments
 (0)