Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Fix crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor committed Mar 22, 2019
1 parent e6d373d commit db27258
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ + (NSDictionary *)customEnvironment
{
NSDictionary* result = nil;
@synchronized (self) {
result = _customEnvironment;
result = [_customEnvironment copy];
}
return result;
}
Expand Down
26 changes: 16 additions & 10 deletions ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m
Original file line number Diff line number Diff line change
Expand Up @@ -965,19 +965,23 @@ - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

- (void)fireTouchEvent:(NSString *)eventName withTouches:(NSSet<UITouch *> *)touches
{
if (_component == nil) {
return;
}

NSMutableArray *resultTouches = [NSMutableArray new];

CGPoint accmOffset = CGPointZero;
UIView* rootView = _component.weexInstance.rootView;
UIView* view = self.view;
while (view && view != rootView) {
if ([view isKindOfClass:[UIScrollView class]]) {
CGPoint offset = ((UIScrollView*)view).contentOffset;
accmOffset.x += offset.x;
accmOffset.y += offset.y;
}
view = view.superview;
}
// UIView* view = self.view;
// while (view && view != rootView) {
// if ([view isKindOfClass:[UIScrollView class]]) {
// CGPoint offset = ((UIScrollView*)view).contentOffset;
// accmOffset.x += offset.x;
// accmOffset.y += offset.y;
// }
// view = view.superview;
// }

for (UITouch *touch in touches) {
CGPoint screenLocation = [touch locationInView:touch.window];
Expand All @@ -1002,7 +1006,9 @@ - (void)fireTouchEvent:(NSString *)eventName withTouches:(NSSet<UITouch *> *)tou
}
}

[resultTouches addObject:mutableResultTouch];
if (mutableResultTouch) { // component is nil, mutableResultTouch will be nil
[resultTouches addObject:mutableResultTouch];
}
}

[_component fireEvent:eventName params:@{@"changedTouches":resultTouches ?: @[]}];
Expand Down
5 changes: 4 additions & 1 deletion ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ - (void)renderWithURL:(NSURL *)url options:(NSDictionary *)options data:(id)data

- (void)renderView:(id)source options:(NSDictionary *)options data:(id)data
{
_options = options;
_options = [options isKindOfClass:[NSDictionary class]] ? options : nil;
_jsData = data;

self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:self.scriptURL];
Expand Down Expand Up @@ -450,6 +450,9 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
NSURL *url = request.URL;
_scriptURL = url;
_jsData = data;
if (![options isKindOfClass:[NSDictionary class]]) {
options = @{};
}
NSMutableDictionary *newOptions = [options mutableCopy] ?: [NSMutableDictionary new];

if (!newOptions[bundleUrlOptionKey]) {
Expand Down

0 comments on commit db27258

Please sign in to comment.