feat:add getX and getY for view

This commit is contained in:
pengfei.zhou 2020-03-03 14:22:33 +08:00 committed by osborn
parent 0641f5e223
commit 35e9f05114
5 changed files with 38 additions and 10 deletions

View File

@ -561,7 +561,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin); return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin);
} }
return 0; return DoricUtils.px2dp(mView.getLeft());
} }
@DoricMethod @DoricMethod
@ -569,7 +569,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin); return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin);
} }
return 0; return DoricUtils.px2dp(mView.getTop());
} }
@DoricMethod @DoricMethod

View File

@ -94,7 +94,7 @@ class MovieVH extends ViewHolder {
[], [],
{ {
layoutConfig: layoutConfig().fit(), layoutConfig: layoutConfig().fit(),
space: 20, space: 0,
padding: { padding: {
top: 20, top: 20,
left: 20, left: 20,
@ -144,29 +144,33 @@ class MovieVM extends ViewModel<MovieModel, MovieVH>{
vh.title.text = state.doubanModel.title vh.title.text = state.doubanModel.title
vh.gallery.children.length = 0 vh.gallery.children.length = 0
const vm = this const vm = this
state.doubanModel.subjects.slice(0, 5).forEach((e, idx) => { state.doubanModel.subjects.forEach((e, idx) => {
vh.gallery.addChild(stack( vh.gallery.addChild(stack(
[ [
image({ image({
layoutConfig: layoutConfig().just(), layoutConfig: layoutConfig().just().configAlignment(Gravity.Center),
width: 270 / 2, width: 270 / 2,
height: 400 / 2, height: 400 / 2,
imageUrl: e.images.large, imageUrl: e.images.large,
scaleX: 1, scaleX: state.selectedIdx == idx ? 1.5 : 1,
scaleY: 1, scaleY: state.selectedIdx == idx ? 1.5 : 1,
onClick: function () { onClick: function () {
vm.updateState(state => state.selectedIdx = idx) 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 => { v.getLocationOnScreen(context).then(ret => {
const centerX = ret.x + v.width / 2; const centerX = ret.x + v.width / 2;
vh.scrolled.scrollBy(context, { x: centerX - Environment.screenWidth / 2, y: 0 }) 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 => { takeNonNull(state.doubanModel.subjects[state.selectedIdx])(it => {

View File

@ -319,6 +319,14 @@ - (NSNumber *)getHeight {
return @(self.view.height); return @(self.view.height);
} }
- (NSNumber *)getX {
return @(self.view.x);
}
- (NSNumber *)getY {
return @(self.view.y);
}
- (NSDictionary *)getLocationOnScreen { - (NSDictionary *)getLocationOnScreen {
CGPoint point = [self.view convertPoint:CGPointMake(0, 0) toView:[UIApplication sharedApplication].windows.lastObject]; CGPoint point = [self.view convertPoint:CGPointMake(0, 0) toView:[UIApplication sharedApplication].windows.lastObject];
return @{@"x": @(point.x), @"y": @(point.y)}; return @{@"x": @(point.x), @"y": @(point.y)};

View File

@ -308,6 +308,14 @@ export abstract class View implements Modeling, IView {
return this.nativeChannel(context, 'getHeight')() as Promise<number> return this.nativeChannel(context, 'getHeight')() as Promise<number>
} }
getX(context: BridgeContext) {
return this.nativeChannel(context, 'getX')() as Promise<number>
}
getY(context: BridgeContext) {
return this.nativeChannel(context, 'getY')() as Promise<number>
}
getLocationOnScreen(context: BridgeContext) { getLocationOnScreen(context: BridgeContext) {
return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }> return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }>
} }

View File

@ -303,6 +303,14 @@ export abstract class View implements Modeling, IView {
return this.nativeChannel(context, 'getHeight')() as Promise<number> return this.nativeChannel(context, 'getHeight')() as Promise<number>
} }
getX(context: BridgeContext) {
return this.nativeChannel(context, 'getX')() as Promise<number>
}
getY(context: BridgeContext) {
return this.nativeChannel(context, 'getY')() as Promise<number>
}
getLocationOnScreen(context: BridgeContext) { getLocationOnScreen(context: BridgeContext) {
return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }> return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }>
} }