You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2018/05/17 06:25:24 UTC

incubator-weex git commit: [WEEX-375][iOS] add Protocol for PageEventNotifyEvent

Repository: incubator-weex
Updated Branches:
  refs/heads/master 621a325e3 -> 1649cb68f


[WEEX-375][iOS] add Protocol for PageEventNotifyEvent

  the handler will called in situations such as rootView clicked,
  scrollView scrolled,a new page start and ended.

feature:375


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1649cb68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1649cb68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1649cb68

Branch: refs/heads/master
Commit: 1649cb68fba6acbade07dc534b6a855afbfab792
Parents: 621a325
Author: acton393 <zh...@gmail.com>
Authored: Thu May 17 12:14:52 2018 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu May 17 12:23:55 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK.xcodeproj/project.pbxproj       |  6 ++++
 .../Sources/Component/WXScrollerComponent.mm    | 12 ++++++++
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m   |  6 ++++
 .../Sources/Protocol/WXPageEventNotifyEvent.h   | 32 ++++++++++++++++++++
 ios/sdk/WeexSDK/Sources/View/WXRootView.h       |  2 +-
 ios/sdk/WeexSDK/Sources/View/WXRootView.m       |  6 ++++
 6 files changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index d5be6cc..a4ce8d2 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -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 */; };
@@ -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>"; };
@@ -1345,6 +1348,7 @@
 				746A2F431DF82607004719D0 /* Network */,
 				77D1611C1C02DD3C0010B15B /* Protocol */,
 				74C27A001CEC4371004E488E /* Supporting Files */,
+				DCE7F1EE20AD358A00D471E7 /* WXPageEventNotifyEvent.h */,
 			);
 			path = Sources;
 			sourceTree = "<group>";
@@ -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 */,
@@ -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 */,

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
index 52bb962..b078300 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
@@ -31,6 +31,7 @@
 #import "WXComponent+Events.h"
 #import "WXScrollerComponent+Layout.h"
 #import "WXCoreLayout.h"
+#import "WXPageEventNotifyEvent.h"
 
 @interface WXScrollerComponentView:UIScrollView
 @end
@@ -99,6 +100,8 @@
     
     BOOL _shouldNotifiAppearDescendantView;
     BOOL _shouldRemoveScrollerListener;
+    CGPoint _scrollStartPoint;
+    CGPoint _scrollEndPoint;
 
     //css_node_t *_scrollerCSSNode;
     
@@ -614,6 +617,8 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
         [_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]};
@@ -731,6 +736,13 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
             [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) {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index ce1154d..d2a66e2 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -50,6 +50,7 @@
 #import "WXBridgeContext.h"
 #import "WXJSCoreBridge.h"
 #import "WXSDKInstance_performance.h"
+#import "WXPageEventNotifyEvent.h"
 
 NSString *const bundleUrlOptionKey = @"bundleUrl";
 
@@ -263,6 +264,11 @@ typedef enum : NSUInteger {
         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);
     

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK/Sources/Protocol/WXPageEventNotifyEvent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXPageEventNotifyEvent.h b/ios/sdk/WeexSDK/Sources/Protocol/WXPageEventNotifyEvent.h
new file mode 100644
index 0000000..d21633d
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Protocol/WXPageEventNotifyEvent.h
@@ -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

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK/Sources/View/WXRootView.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXRootView.h b/ios/sdk/WeexSDK/Sources/View/WXRootView.h
index 2f1453f..24782e8 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXRootView.h
+++ b/ios/sdk/WeexSDK/Sources/View/WXRootView.h
@@ -24,6 +24,6 @@
 
 @property (nonatomic, weak) WXSDKInstance *instance;
 
-- (BOOL) isHasEvent;
+- (BOOL)isHasEvent;
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1649cb68/ios/sdk/WeexSDK/Sources/View/WXRootView.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXRootView.m b/ios/sdk/WeexSDK/Sources/View/WXRootView.m
index 4d35f48..3cc8a36 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXRootView.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXRootView.m
@@ -19,6 +19,8 @@
 
 #import "WXRootView.h"
 #import "WXSDKInstance.h"
+#import "WXPageEventNotifyEvent.h"
+#import "WXSDKEngine.h"
 
 @interface WXRootView()
 
@@ -45,6 +47,10 @@
 - (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];
 }