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

Commit

Permalink
[WEEX-375][iOS] add Protocol for PageEventNotifyEvent
Browse files Browse the repository at this point in the history
  the handler will called in situations such as rootView clicked,
  scrollView scrolled,a new page start and ended.

feature:375
  • Loading branch information
acton393 committed May 17, 2018
1 parent 854df9d commit 24552b1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ios/sdk/WeexSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@
DCE2CF9B1F46D4220021BDC4 /* WXVoiceOverModule.h in Headers */ = {isa = PBXBuildFile; fileRef = DCE2CF991F46D4220021BDC4 /* WXVoiceOverModule.h */; settings = {ATTRIBUTES = (Public, ); }; };
DCE2CF9C1F46D4310021BDC4 /* WXVoiceOverModule.h in Headers */ = {isa = PBXBuildFile; fileRef = DCE2CF991F46D4220021BDC4 /* WXVoiceOverModule.h */; settings = {ATTRIBUTES = (Public, ); }; };
DCE2CF9D1F46D4370021BDC4 /* WXVoiceOverModule.m in Sources */ = {isa = PBXBuildFile; fileRef = DCE2CF981F46D4220021BDC4 /* WXVoiceOverModule.m */; };
DCE7F1EF20AD358A00D471E7 /* WXPageEventNotifyEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = DCE7F1EE20AD358A00D471E7 /* WXPageEventNotifyEvent.h */; };
DCE7F1F020AD358A00D471E7 /* WXPageEventNotifyEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = DCE7F1EE20AD358A00D471E7 /* WXPageEventNotifyEvent.h */; };
DCEA54621F2B7DB4000ECB23 /* WXTracingManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C4E97D311F1EF46D00ABC314 /* WXTracingManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
DCEA54631F2B7DBA000ECB23 /* WXTracingManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C4E97D321F1EF46D00ABC314 /* WXTracingManager.m */; };
DCF087611DCAE161005CD6EB /* WXInvocationConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = DCF0875F1DCAE161005CD6EB /* WXInvocationConfig.h */; };
Expand Down Expand Up @@ -977,6 +979,7 @@
DCDFED001E68238F00C228D7 /* WXJSExceptionProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXJSExceptionProtocol.h; sourceTree = "<group>"; };
DCE2CF981F46D4220021BDC4 /* WXVoiceOverModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXVoiceOverModule.m; sourceTree = "<group>"; };
DCE2CF991F46D4220021BDC4 /* WXVoiceOverModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXVoiceOverModule.h; sourceTree = "<group>"; };
DCE7F1EE20AD358A00D471E7 /* WXPageEventNotifyEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WXPageEventNotifyEvent.h; path = Protocol/WXPageEventNotifyEvent.h; sourceTree = "<group>"; };
DCF0875F1DCAE161005CD6EB /* WXInvocationConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXInvocationConfig.h; sourceTree = "<group>"; };
DCF087601DCAE161005CD6EB /* WXInvocationConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXInvocationConfig.m; sourceTree = "<group>"; };
DCF0CD9D1EAF3A6B0062CA8F /* native-bundle-main.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; name = "native-bundle-main.js"; path = "../../../../pre-build/native-bundle-main.js"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1345,6 +1348,7 @@
746A2F431DF82607004719D0 /* Network */,
77D1611C1C02DD3C0010B15B /* Protocol */,
74C27A001CEC4371004E488E /* Supporting Files */,
DCE7F1EE20AD358A00D471E7 /* WXPageEventNotifyEvent.h */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -1803,6 +1807,7 @@
77D161301C02DE4E0010B15B /* WXComponent.h in Headers */,
2AFEB17B1C747139000507FA /* WXInstanceWrap.h in Headers */,
744BEA551D05178F00452B5D /* WXComponent+Display.h in Headers */,
DCE7F1EF20AD358A00D471E7 /* WXPageEventNotifyEvent.h in Headers */,
741081231CED6756001BC6E5 /* WXComponentFactory.h in Headers */,
59D3CA4A1CFC3CE1008835DC /* NSTimer+Weex.h in Headers */,
C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */,
Expand Down Expand Up @@ -1893,6 +1898,7 @@
C42E8FAD1F3C7C3F001EBE9D /* WXExtendCallNativeManager.h in Headers */,
DCA445CB1EFA590600D0CFA8 /* WXComponent+Layout.h in Headers */,
DCA4460F1EFA5A8100D0CFA8 /* WXDiffUtil.h in Headers */,
DCE7F1F020AD358A00D471E7 /* WXPageEventNotifyEvent.h in Headers */,
DCA445F91EFA5A3700D0CFA8 /* WXClipboardModule.h in Headers */,
DCA445FD1EFA5A4000D0CFA8 /* WXAnimationModule.h in Headers */,
DCA446101EFA5A8500D0CFA8 /* WXBridgeMethod.h in Headers */,
Expand Down
12 changes: 12 additions & 0 deletions ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "WXComponent+Events.h"
#import "WXScrollerComponent+Layout.h"
#import "WXCoreLayout.h"
#import "WXPageEventNotifyEvent.h"

@interface WXScrollerComponentView:UIScrollView
@end
Expand Down Expand Up @@ -99,6 +100,8 @@ @implementation WXScrollerComponent

BOOL _shouldNotifiAppearDescendantView;
BOOL _shouldRemoveScrollerListener;
CGPoint _scrollStartPoint;
CGPoint _scrollEndPoint;

//css_node_t *_scrollerCSSNode;

Expand Down Expand Up @@ -614,6 +617,8 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
[_refreshComponent setIndicatorHidden:NO];
}

_scrollStartPoint = scrollView.contentOffset;

if (_scrollStartEvent) {
CGFloat scaleFactor = self.weexInstance.pixelScaleFactor;
NSDictionary *contentSizeData = @{@"width":[NSNumber numberWithFloat:scrollView.contentSize.width / scaleFactor],@"height":[NSNumber numberWithFloat:scrollView.contentSize.height / scaleFactor]};
Expand Down Expand Up @@ -731,6 +736,13 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
[self fireEvent:@"scrollend" params:@{@"contentSize":contentSizeData,@"contentOffset":contentOffsetData} domChanges:nil];
}
}
if (!_isScrolling) {
_scrollEndPoint = scrollView.contentOffset;
id<WXPageEventNotifyEventProtocol> eventNotify = [WXSDKEngine handlerForProtocol:@protocol(WXPageEventNotifyEventProtocol)];
if ([eventNotify respondsToSelector:@selector(notifyScrollEvent:from:to:)]) {
[eventNotify notifyScrollEvent:self.weexInstance.instanceId from:_scrollStartPoint to:_scrollEndPoint];
}
}

NSHashTable *delegates = [_delegates copy];
for (id<UIScrollViewDelegate> delegate in delegates) {
Expand Down
6 changes: 6 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#import "WXBridgeContext.h"
#import "WXJSCoreBridge.h"
#import "WXSDKInstance_performance.h"
#import "WXPageEventNotifyEvent.h"

NSString *const bundleUrlOptionKey = @"bundleUrl";

Expand Down Expand Up @@ -263,6 +264,11 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString
self.userInfo[@"jsMainBundleStringContentMd5"] = [WXUtility md5:mainBundleString];
}

id<WXPageEventNotifyEventProtocol> pageEvent = [WXSDKEngine handlerForProtocol:@protocol(WXPageEventNotifyEventProtocol)];
if ([pageEvent respondsToSelector:@selector(pageDestroy:)]) {
[pageEvent pageStart:self.instanceId];
}

WX_MONITOR_INSTANCE_PERF_START(WXPTFirstScreenRender, self);
WX_MONITOR_INSTANCE_PERF_START(WXPTAllRender, self);

Expand Down
32 changes: 32 additions & 0 deletions ios/sdk/WeexSDK/Sources/Protocol/WXPageEventNotifyEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#import "WXJSExceptionInfo.h"

@protocol WXPageEventNotifyEventProtocol <NSObject>

- (void)hitTest:(CGPoint)point withEvent:(UIEvent *)event withView:(UIView*)view;

- (void)notifyScrollEvent:(NSString*)instanceId from:(CGPoint)from to:(CGPoint)to;

- (void)pageStart:(NSString*)instanceId;

- (void)pageDestroy:(NSString*)instanceId;

@end
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/View/WXRootView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

@property (nonatomic, weak) WXSDKInstance *instance;

- (BOOL) isHasEvent;
- (BOOL)isHasEvent;

@end
6 changes: 6 additions & 0 deletions ios/sdk/WeexSDK/Sources/View/WXRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#import "WXRootView.h"
#import "WXSDKInstance.h"
#import "WXPageEventNotifyEvent.h"
#import "WXSDKEngine.h"

@interface WXRootView()

Expand All @@ -45,6 +47,10 @@ - (void)setFrame:(CGRect)frame
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
_mHasEvent = TRUE;
id<WXPageEventNotifyEventProtocol> pageEventNotify = [WXSDKEngine handlerForProtocol:@protocol(WXPageEventNotifyEventProtocol)];
if ([pageEventNotify respondsToSelector:@selector(hitTest:withEvent:withView:)]){
[pageEventNotify hitTest:point withEvent:event withView:self];
}
return [super hitTest:point withEvent:event];
}

Expand Down

0 comments on commit 24552b1

Please sign in to comment.