feat:scroller add scrollBy
This commit is contained in:
parent
6d7562877e
commit
0641f5e223
@ -136,4 +136,20 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
|
||||
DoricUtils.dp2px(offset.getProperty("y").asNumber().toFloat()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void scrollBy(JSObject params) {
|
||||
boolean animated = false;
|
||||
if (params.getProperty("animated").isBoolean()) {
|
||||
animated = params.getProperty("animated").asBoolean().value();
|
||||
}
|
||||
JSObject offset = params.getProperty("offset").asObject();
|
||||
if (animated) {
|
||||
this.mView.smoothScrollBy(DoricUtils.dp2px(offset.getProperty("x").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(offset.getProperty("y").asNumber().toFloat()));
|
||||
} else {
|
||||
this.mView.scrollBy(DoricUtils.dp2px(offset.getProperty("x").asNumber().toFloat()),
|
||||
DoricUtils.dp2px(offset.getProperty("y").asNumber().toFloat()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Group, text, gravity, Color, LayoutSpec, vlayout, hlayout, layoutConfig, scroller, Text, ViewHolder, VMPanel, ViewModel, network, loge, HLayout, stack, image, Gravity, takeNonNull, Scroller } from "doric";
|
||||
import { Group, text, gravity, Color, LayoutSpec, vlayout, hlayout, layoutConfig, scroller, Text, ViewHolder, VMPanel, ViewModel, network, loge, HLayout, stack, image, Gravity, takeNonNull, Scroller, Image } from "doric";
|
||||
import { colors } from "./utils";
|
||||
|
||||
interface DoubanModel {
|
||||
@ -109,6 +109,9 @@ class MovieVH extends ViewHolder {
|
||||
}),
|
||||
vlayout(
|
||||
[
|
||||
text({
|
||||
text: "↑",
|
||||
}),
|
||||
this.movieTitle = text({
|
||||
textSize: 20,
|
||||
}),
|
||||
@ -123,7 +126,7 @@ class MovieVH extends ViewHolder {
|
||||
],
|
||||
{
|
||||
layoutConfig: layoutConfig().most(),
|
||||
space: 50,
|
||||
space: 0,
|
||||
}).in(root)
|
||||
}
|
||||
|
||||
@ -140,17 +143,26 @@ class MovieVM extends ViewModel<MovieModel, MovieVH>{
|
||||
if (state.doubanModel) {
|
||||
vh.title.text = state.doubanModel.title
|
||||
vh.gallery.children.length = 0
|
||||
const vm = this
|
||||
state.doubanModel.subjects.slice(0, 5).forEach((e, idx) => {
|
||||
vh.gallery.addChild(stack(
|
||||
[
|
||||
image({
|
||||
layoutConfig: layoutConfig().just(),
|
||||
width: 270 / 2 * (idx == state.selectedIdx ? 1.2 : 1),
|
||||
height: 400 / 2 * (idx == state.selectedIdx ? 1.2 : 1),
|
||||
width: 270 / 2,
|
||||
height: 400 / 2,
|
||||
imageUrl: e.images.large,
|
||||
onClick: () => {
|
||||
this.updateState(state => state.selectedIdx = idx)
|
||||
vh.scrolled.contentOffset = { x: idx * 200, y: 0 }
|
||||
scaleX: 1,
|
||||
scaleY: 1,
|
||||
onClick: function () {
|
||||
vm.updateState(state => state.selectedIdx = idx)
|
||||
const v = this as Image
|
||||
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
|
||||
})
|
||||
},
|
||||
})
|
||||
],
|
||||
|
@ -144,4 +144,14 @@ - (void)scrollTo:(NSDictionary *)params {
|
||||
CGPoint offset = CGPointMake([offsetDic[@"x"] floatValue], [offsetDic[@"y"] floatValue]);
|
||||
[self.view setContentOffset:offset animated:animated];
|
||||
}
|
||||
|
||||
- (void)scrollBy:(NSDictionary *)params {
|
||||
BOOL animated = [params[@"animated"] boolValue];
|
||||
NSDictionary *offsetDic = params[@"offset"];
|
||||
CGPoint offset = CGPointMake([offsetDic[@"x"] floatValue], [offsetDic[@"y"] floatValue]);
|
||||
[self.view setContentOffset:CGPointMake(
|
||||
MIN(self.view.contentSize.width - self.view.width, MAX(0, offset.x + self.view.contentOffset.x)),
|
||||
MIN(self.view.contentSize.height - self.view.height, MAX(0, offset.y + self.view.contentOffset.y)))
|
||||
animated:animated];
|
||||
}
|
||||
@end
|
||||
|
@ -2016,6 +2016,9 @@ var Scroller = /** @class */ (function (_super) {
|
||||
Scroller.prototype.scrollTo = function (context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset: offset, animated: animated });
|
||||
};
|
||||
Scroller.prototype.scrollBy = function (context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset: offset, animated: animated });
|
||||
};
|
||||
__decorate$7([
|
||||
Property,
|
||||
__metadata$7("design:type", Object)
|
||||
|
@ -1496,6 +1496,9 @@ class Scroller extends Superview {
|
||||
scrollTo(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset, animated });
|
||||
}
|
||||
scrollBy(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset, animated });
|
||||
}
|
||||
}
|
||||
__decorate$7([
|
||||
Property,
|
||||
|
@ -2955,6 +2955,9 @@ class Scroller extends Superview {
|
||||
scrollTo(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset, animated });
|
||||
}
|
||||
scrollBy(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset, animated });
|
||||
}
|
||||
}
|
||||
__decorate$7([
|
||||
Property,
|
||||
|
4
doric-js/index.d.ts
vendored
4
doric-js/index.d.ts
vendored
@ -591,6 +591,10 @@ declare module 'doric/lib/src/widget/scroller' {
|
||||
x: number;
|
||||
y: number;
|
||||
}, animated?: boolean): Promise<any>;
|
||||
scrollBy(context: BridgeContext, offset: {
|
||||
x: number;
|
||||
y: number;
|
||||
}, animated?: boolean): Promise<any>;
|
||||
}
|
||||
}
|
||||
|
||||
|
4
doric-js/lib/src/widget/scroller.d.ts
vendored
4
doric-js/lib/src/widget/scroller.d.ts
vendored
@ -20,4 +20,8 @@ export declare class Scroller extends Superview implements IScroller {
|
||||
x: number;
|
||||
y: number;
|
||||
}, animated?: boolean): Promise<any>;
|
||||
scrollBy(context: BridgeContext, offset: {
|
||||
x: number;
|
||||
y: number;
|
||||
}, animated?: boolean): Promise<any>;
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ export class Scroller extends Superview {
|
||||
scrollTo(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset, animated });
|
||||
}
|
||||
scrollBy(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset, animated });
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
Property,
|
||||
|
@ -52,4 +52,8 @@ export class Scroller extends Superview implements IScroller {
|
||||
scrollTo(context: BridgeContext, offset: { x: number, y: number }, animated?: boolean) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset, animated })
|
||||
}
|
||||
|
||||
scrollBy(context: BridgeContext, offset: { x: number, y: number }, animated?: boolean) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset, animated })
|
||||
}
|
||||
}
|
3
doric-web/dist/index.js
vendored
3
doric-web/dist/index.js
vendored
@ -3013,6 +3013,9 @@ class Scroller extends Superview {
|
||||
scrollTo(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollTo")({ offset, animated });
|
||||
}
|
||||
scrollBy(context, offset, animated) {
|
||||
return this.nativeChannel(context, "scrollBy")({ offset, animated });
|
||||
}
|
||||
}
|
||||
__decorate$7([
|
||||
Property,
|
||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user