feat:optimize iOS Transform setting

This commit is contained in:
pengfei.zhou 2020-03-03 14:43:49 +08:00 committed by osborn
parent 35e9f05114
commit 0fa121e54f
10 changed files with 42 additions and 5 deletions

View File

@ -139,6 +139,7 @@ class MovieVM extends ViewModel<MovieModel, MovieVH>{
this.updateState(state => state.doubanModel = JSON.parse(ret.data) as DoubanModel)
})
}
onBind(state: MovieModel, vh: MovieVH) {
if (state.doubanModel) {
vh.title.text = state.doubanModel.title
@ -162,7 +163,7 @@ class MovieVM extends ViewModel<MovieModel, MovieVH>{
}
v.getLocationOnScreen(context).then(ret => {
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 }, true)
})
},
})

View File

@ -152,13 +152,15 @@ - (void)transformProperties {
if (self.rotation) {
transform = CGAffineTransformRotate(transform, (self.rotation.floatValue ?: 0) * M_PI);
}
if (!CGAffineTransformEqualToTransform(transform, self.view.transform)) {
self.view.transform = transform;
}
if (self.pivotX || self.pivotY) {
self.view.layer.anchorPoint = CGPointMake(self.pivotX.floatValue
?: 0.5f, self.pivotY.floatValue ?: 0.5f);
}
if (!CGAffineTransformEqualToTransform(transform, self.view.transform)) {
dispatch_async(dispatch_get_main_queue(), ^{
self.view.transform = transform;
});
}
}
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {

View File

@ -367,6 +367,12 @@ var View = /** @class */ (function () {
View.prototype.getHeight = function (context) {
return this.nativeChannel(context, 'getHeight')();
};
View.prototype.getX = function (context) {
return this.nativeChannel(context, 'getX')();
};
View.prototype.getY = function (context) {
return this.nativeChannel(context, 'getY')();
};
View.prototype.getLocationOnScreen = function (context) {
return this.nativeChannel(context, "getLocationOnScreen")();
};

View File

@ -283,6 +283,12 @@ class View {
getHeight(context) {
return this.nativeChannel(context, 'getHeight')();
}
getX(context) {
return this.nativeChannel(context, 'getX')();
}
getY(context) {
return this.nativeChannel(context, 'getY')();
}
getLocationOnScreen(context) {
return this.nativeChannel(context, "getLocationOnScreen")();
}

View File

@ -1742,6 +1742,12 @@ class View {
getHeight(context) {
return this.nativeChannel(context, 'getHeight')();
}
getX(context) {
return this.nativeChannel(context, 'getX')();
}
getY(context) {
return this.nativeChannel(context, 'getY')();
}
getLocationOnScreen(context) {
return this.nativeChannel(context, "getLocationOnScreen")();
}

2
doric-js/index.d.ts vendored
View File

@ -241,6 +241,8 @@ declare module 'doric/lib/src/ui/view' {
nativeChannel(context: BridgeContext, name: string): (args?: any) => Promise<any>;
getWidth(context: BridgeContext): Promise<number>;
getHeight(context: BridgeContext): Promise<number>;
getX(context: BridgeContext): Promise<number>;
getY(context: BridgeContext): Promise<number>;
getLocationOnScreen(context: BridgeContext): Promise<{
x: number;
y: number;

View File

@ -134,6 +134,8 @@ export declare abstract class View implements Modeling, IView {
nativeChannel(context: BridgeContext, name: string): (args?: any) => Promise<any>;
getWidth(context: BridgeContext): Promise<number>;
getHeight(context: BridgeContext): Promise<number>;
getX(context: BridgeContext): Promise<number>;
getY(context: BridgeContext): Promise<number>;
getLocationOnScreen(context: BridgeContext): Promise<{
x: number;
y: number;

View File

@ -168,6 +168,12 @@ export class View {
getHeight(context) {
return this.nativeChannel(context, 'getHeight')();
}
getX(context) {
return this.nativeChannel(context, 'getX')();
}
getY(context) {
return this.nativeChannel(context, 'getY')();
}
getLocationOnScreen(context) {
return this.nativeChannel(context, "getLocationOnScreen")();
}

View File

@ -1800,6 +1800,12 @@ class View {
getHeight(context) {
return this.nativeChannel(context, 'getHeight')();
}
getX(context) {
return this.nativeChannel(context, 'getX')();
}
getY(context) {
return this.nativeChannel(context, 'getY')();
}
getLocationOnScreen(context) {
return this.nativeChannel(context, "getLocationOnScreen")();
}

File diff suppressed because one or more lines are too long