feat:add getX and getY for view
This commit is contained in:
parent
0641f5e223
commit
35e9f05114
@ -561,7 +561,7 @@ public abstract class ViewNode<T extends View> 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<T extends View> extends DoricContextHolder {
|
||||
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||
return DoricUtils.px2dp(((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin);
|
||||
}
|
||||
return 0;
|
||||
return DoricUtils.px2dp(mView.getTop());
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
|
@ -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<MovieModel, MovieVH>{
|
||||
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 => {
|
||||
|
@ -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)};
|
||||
|
@ -308,6 +308,14 @@ export abstract class View implements Modeling, IView {
|
||||
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) {
|
||||
return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }>
|
||||
}
|
||||
|
@ -303,6 +303,14 @@ export abstract class View implements Modeling, IView {
|
||||
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) {
|
||||
return this.nativeChannel(context, "getLocationOnScreen")() as Promise<{ x: number, y: number }>
|
||||
}
|
||||
|
Reference in New Issue
Block a user