Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into qking_18_01_12_merge
Browse files Browse the repository at this point in the history
* origin/master:
  [android] modify playground app camera runtime permission request behavior (apache#1221)
  [WEEX][Android] Support  Downgrade To Full Page Root Instance (apache#1952)
  [WEEX][Android] Weex Bugfix For Scroller Remove Failed Because Of Edit Of Scroller Touch Event (apache#2005)
  [WEEX][Android] When View Not InstanceOf WXGestureObservable, mGestureType is Null, remove event has none affect, (apache#1968)
  [iOS] fix customEnvironment crash
  * [iOS] Add support for custom event with stoppropagation
  • Loading branch information
pengtaopt committed Jan 10, 2019
2 parents d185614 + b874c1f commit 0cd4eff
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startActivity(new Intent(this, CaptureActivity.class));
} else if (requestCode == WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
Toast.makeText(this, "request camara permission fail!", Toast.LENGTH_SHORT).show();
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startActivity(new Intent(this, CaptureActivity.class));
} else {
Toast.makeText(this, "request camara permission fail!", Toast.LENGTH_SHORT).show();
}
} else if (requestCode == WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE
&& grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.Toast;

Expand Down Expand Up @@ -57,8 +60,8 @@ public void openURL(String url) {
if ("weex://go/scan".equals(url)) {
if (ContextCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mWXSDKInstance.getContext(), Manifest.permission.CAMERA)) {
Toast.makeText(mWXSDKInstance.getContext(), "Weex playground need the camera permission to scan QR code", Toast.LENGTH_SHORT).show();
} else {
showCameraPermissionRationale();
} else{
ActivityCompat.requestPermissions((Activity) mWXSDKInstance.getContext(), new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
}
} else {
Expand Down Expand Up @@ -89,6 +92,21 @@ public void openURL(String url) {
mWXSDKInstance.fireModuleEvent("event", this, params);
}
}

private void showCameraPermissionRationale() {
if (mWXSDKInstance.getContext() instanceof AppCompatActivity) {
AlertDialog.Builder builder = new AlertDialog.Builder(((AppCompatActivity) mWXSDKInstance.getContext()));
builder.setMessage("Weex playground need the camera permission to scan QR code");
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions((Activity) mWXSDKInstance.getContext(), new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
}
});
builder.create().show();
}
}

/*
* a test method for macaca case, you can fire globalEvent when download finish、device shaked and so on.
* @param event event name
Expand All @@ -108,9 +126,13 @@ public void fireNativeGlobalEvent(String event, JSCallback callback) {

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mWXSDKInstance.getContext().startActivity(new Intent(mWXSDKInstance.getContext(), CaptureActivity.class));
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mWXSDKInstance.getContext().startActivity(new Intent(mWXSDKInstance.getContext(), CaptureActivity.class));
} else {
Toast.makeText(mWXSDKInstance.getContext(), "request camara permission fail!", Toast.LENGTH_SHORT).show();
}
}
}
}
13 changes: 13 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan

private List<String> mLayerOverFlowListeners;

private WXSDKInstance mParentInstance;

public List<String> getLayerOverFlowListeners() {
return mLayerOverFlowListeners;
}
Expand Down Expand Up @@ -1499,6 +1501,14 @@ public void run() {
mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime;
}

public WXSDKInstance getParentInstance() {
return mParentInstance;
}

public void setParentInstance(WXSDKInstance mParentInstance) {
this.mParentInstance = mParentInstance;
}

private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
Expand All @@ -1522,6 +1532,9 @@ private void destroyView(View rootView) {

public synchronized void destroy() {
if(!isDestroy()) {
if(mParentInstance != null){
mParentInstance = null;
}
mApmForInstance.onEnd();
if(mRendered) {
WXSDKManager.getInstance().destroyInstance(mInstanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.common;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.JSMethod;

/**
Expand All @@ -28,7 +29,13 @@ public class WXInstanceWrap extends WXModule {
@JSMethod
public void error(String type, String code, String info) {
if (mWXSDKInstance != null) {
mWXSDKInstance.onRenderError(type + "|" + code, info);
WXSDKInstance root = mWXSDKInstance;
if(info != null && info.contains("downgrade_to_root")){
while (root.getParentInstance() != null){
root = root.getParentInstance();
}
}
root.onRenderError(type + "|" + code, info);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1501,16 +1501,19 @@ public void removeEvent(String type) {
if (TextUtils.isEmpty(type)) {
return;
}
if (getEvents() == null || mAppendEvents == null || mGestureType == null) {
return;
}

if (type.equals(Constants.Event.LAYEROVERFLOW))
removeLayerOverFlowListener(getRef());

getEvents().remove(type);
mAppendEvents.remove(type);//only clean append events, not dom's events.
mGestureType.remove(type);
if(getEvents() != null){
getEvents().remove(type);
}
if(mAppendEvents != null) {
mAppendEvents.remove(type);//only clean append events, not dom's events.
}
if(mGestureType != null){
mGestureType.remove(type);
}
removeEventFromView(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private static final int getLevel(WXEmbed embed){

private WXSDKInstance createInstance() {
WXSDKInstance sdkInstance = getInstance().createNestedInstance(this);

sdkInstance.setParentInstance(getInstance());
boolean needsAdd = !getAttrs().containsKey("disableInstanceVisibleListener");
if(needsAdd){ //prevent switch off fire viewappear event twice
getInstance().addOnInstanceVisibleListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
Expand Down Expand Up @@ -329,7 +331,12 @@ && getInstance().getRootView() != null
getInstance().removeFixedView(child.getHostView());
} else if (getRealView() != null) {
if (!child.isVirtualComponent()) {
getRealView().removeView(child.getHostView());
ViewParent parent = child.getHostView().getParent();
if(parent != null && parent instanceof ViewGroup){
((ViewGroup) parent).removeView(child.getHostView());
}else{
getRealView().removeView(child.getHostView());
}
} else {
child.removeVirtualComponent();
}
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ typedef id (^WXDataBindingBlock)(NSDictionary *data, BOOL *needUpdate);
BOOL _listenVerticalPan;

BOOL _listenStopPropagation;
BOOL _customEvent;
NSString *_stopPropagationName;
WXTouchGestureRecognizer* _touchGesture;

Expand Down
4 changes: 4 additions & 0 deletions ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ - (BOOL)gestureShouldStopPropagation:(UIGestureRecognizer *)gestureRecognizer sh
}
BOOL stopPropagation = [[WXEventManager sharedManager]stopPropagation:self.weexInstance.instanceId ref:ref type:_stopPropagationName params:@{@"changedTouches":resultTouch ? @[resultTouch] : @[],@"action":touchState}];
touch.wx_stopPropagation = stopPropagation ? @1 : @0;

//only custom event on custom component will make not receive touch
//you can use custom-event="yes" to enable this feature
return _customEvent ? !stopPropagation : YES;
}
}
return YES;
Expand Down
4 changes: 4 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ - (instancetype)initWithRef:(NSString *)ref
_clipRadius = [WXConvert NSString:attributes[@"clipRadius"]];
}

if (attributes[@"customEvent"]) {
_customEvent = [WXConvert BOOL:attributes[@"customEvent"]];
}

#ifdef DEBUG
WXLogDebug(@"flexLayout -> init component: ref : %@ , styles: %@",ref,styles);
WXLogDebug(@"flexLayout -> init component: ref : %@ , attributes: %@",ref,attributes);
Expand Down
5 changes: 1 addition & 4 deletions ios/sdk/WeexSDK/Sources/Utility/WXLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ + (instancetype)sharedInstance

+ (void)setLogLevel:(WXLogLevel)level
{
if (((WXLog*)[self sharedInstance])->_logLevel != level) {
((WXLog*)[self sharedInstance])->_logLevel = level;
((WXLog*)[self sharedInstance])->_logLevel = level;

[[WXSDKManager bridgeMgr] resetEnvironment];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
Class propertyClass = NSClassFromString(@"WXTracingViewControllerManager");
Expand Down
1 change: 0 additions & 1 deletion ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ + (NSDictionary *)getEnvironment
@"deviceWidth":@(deviceWidth * scale),
@"deviceHeight":@(deviceHeight * scale),
@"scale":@(scale),
@"logLevel":[WXLog logLevelString] ?: @"error",
@"layoutDirection": [self getEnvLayoutDirection] == WXLayoutDirectionRTL ? @"rtl" : @"ltr"
}];

Expand Down

0 comments on commit 0cd4eff

Please sign in to comment.