From 35e9f051141bd2e3cc0464b27ba8ba43916416f5 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 3 Mar 2020 14:22:33 +0800 Subject: [PATCH] feat:add getX and getY for view --- .../main/java/pub/doric/shader/ViewNode.java | 4 ++-- doric-demo/src/ScrolledSliderDemo.ts | 20 +++++++++++-------- doric-iOS/Pod/Classes/Shader/DoricViewNode.m | 8 ++++++++ doric-js/src/ui/view.es5.ts | 8 ++++++++ doric-js/src/ui/view.ts | 8 ++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java index b5fa9c95..3d1c98f1 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -561,7 +561,7 @@ public abstract class ViewNode extends DoricContextHolder { if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin); } - return 0; + return DoricUtils.px2dp(mView.getLeft()); } @DoricMethod @@ -569,7 +569,7 @@ public abstract class ViewNode extends DoricContextHolder { if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin); } - return 0; + return DoricUtils.px2dp(mView.getTop()); } @DoricMethod diff --git a/doric-demo/src/ScrolledSliderDemo.ts b/doric-demo/src/ScrolledSliderDemo.ts index 97757db6..a4d00272 100644 --- a/doric-demo/src/ScrolledSliderDemo.ts +++ b/doric-demo/src/ScrolledSliderDemo.ts @@ -94,7 +94,7 @@ class MovieVH extends ViewHolder { [], { layoutConfig: layoutConfig().fit(), - space: 20, + space: 0, padding: { top: 20, left: 20, @@ -144,29 +144,33 @@ class MovieVM extends ViewModel{ vh.title.text = state.doubanModel.title vh.gallery.children.length = 0 const vm = this - state.doubanModel.subjects.slice(0, 5).forEach((e, idx) => { + state.doubanModel.subjects.forEach((e, idx) => { vh.gallery.addChild(stack( [ image({ - layoutConfig: layoutConfig().just(), + layoutConfig: layoutConfig().just().configAlignment(Gravity.Center), width: 270 / 2, height: 400 / 2, imageUrl: e.images.large, - scaleX: 1, - scaleY: 1, + scaleX: state.selectedIdx == idx ? 1.5 : 1, + scaleY: state.selectedIdx == idx ? 1.5 : 1, onClick: function () { vm.updateState(state => state.selectedIdx = idx) - const v = this as Image + const v = (this as Image).superview + if (v == undefined) { + return + } v.getLocationOnScreen(context).then(ret => { const centerX = ret.x + v.width / 2; vh.scrolled.scrollBy(context, { x: centerX - Environment.screenWidth / 2, y: 0 }) - v.scaleX = 1.2 - v.scaleY = 1.2 }) }, }) ], { + layoutConfig: layoutConfig().just(), + width: 270 / 2 * 1.5, + height: 400 / 2 * 1.5, })) }) takeNonNull(state.doubanModel.subjects[state.selectedIdx])(it => { diff --git a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m index 7387eb78..6b103a5a 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m @@ -319,6 +319,14 @@ - (NSNumber *)getHeight { return @(self.view.height); } +- (NSNumber *)getX { + return @(self.view.x); +} + +- (NSNumber *)getY { + return @(self.view.y); +} + - (NSDictionary *)getLocationOnScreen { CGPoint point = [self.view convertPoint:CGPointMake(0, 0) toView:[UIApplication sharedApplication].windows.lastObject]; return @{@"x": @(point.x), @"y": @(point.y)}; diff --git a/doric-js/src/ui/view.es5.ts b/doric-js/src/ui/view.es5.ts index 6057ae99..accec06b 100644 --- a/doric-js/src/ui/view.es5.ts +++ b/doric-js/src/ui/view.es5.ts @@ -308,6 +308,14 @@ export abstract class View implements Modeling, IView { return this.nativeChannel(context, 'getHeight')() as Promise } + getX(context: BridgeContext) { + return this.nativeChannel(context, 'getX')() as Promise + } + + getY(context: BridgeContext) { + return this.nativeChannel(context, 'getY')() as Promise + } + getLocationOnScreen(context: BridgeContext) { return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }> } diff --git a/doric-js/src/ui/view.ts b/doric-js/src/ui/view.ts index 3d7377f5..65578050 100644 --- a/doric-js/src/ui/view.ts +++ b/doric-js/src/ui/view.ts @@ -303,6 +303,14 @@ export abstract class View implements Modeling, IView { return this.nativeChannel(context, 'getHeight')() as Promise } + getX(context: BridgeContext) { + return this.nativeChannel(context, 'getX')() as Promise + } + + getY(context: BridgeContext) { + return this.nativeChannel(context, 'getY')() as Promise + } + getLocationOnScreen(context: BridgeContext) { return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }> }