add flexscroller

This commit is contained in:
pengfei.zhou 2020-04-11 11:02:51 +08:00 committed by osborn
parent 6bcc6d014c
commit 4e537eed47
20 changed files with 685 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import { Group, Panel, text, gravity, Color, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig, stack, Gravity, flexlayout } from "doric"; import { Group, Panel, text, gravity, Color, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig, stack, Gravity, flexlayout, flexScroller } from "doric";
import { FlexDirection, Wrap, Justify, Align, FlexTypedValue, OverFlow } from "doric/lib/src/util/flexbox"; import { FlexDirection, Wrap, Justify, Align, FlexTypedValue, OverFlow } from "doric/lib/src/util/flexbox";
import { colors } from "./utils"; import { colors } from "./utils";
@ -55,6 +55,43 @@ class LayoutDemo extends Panel {
width: 250, width: 250,
height: 250, height: 250,
} }
).in(root) )
//.in(root)
flexScroller(
[
stack([],
{
backgroundColor: colors[1],
flexConfig: {
width: 500,
height: 100,
}
}),
stack([],
{
backgroundColor: colors[2],
flexConfig: {
width: 100,
height: 100,
}
}),
stack([],
{
backgroundColor: colors[3],
flexConfig: {
width: 100,
height: 100,
}
}),
],
{
backgroundColor: Color.GRAY.alpha(0.3),
layoutConfig: layoutConfig().just(),
width: 300,
height: 300,
flexConfig: {
overFlow: OverFlow.HIDDEN,
}
}).in(root)
} }
} }

View File

@ -53,6 +53,7 @@
#import "DoricSwitchNode.h" #import "DoricSwitchNode.h"
#import "DoricNotchPlugin.h" #import "DoricNotchPlugin.h"
#import "DoricFlexNode.h" #import "DoricFlexNode.h"
#import "DoricFlexScrollerNode.h"
@interface DoricLibraries : NSObject @interface DoricLibraries : NSObject
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries; @property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
@ -141,6 +142,7 @@ - (void)innerRegister {
[self registerViewNode:DoricDraggableNode.class withName:@"Draggable"]; [self registerViewNode:DoricDraggableNode.class withName:@"Draggable"];
[self registerViewNode:DoricSwitchNode.class withName:@"Switch"]; [self registerViewNode:DoricSwitchNode.class withName:@"Switch"];
[self registerViewNode:DoricFlexNode.class withName:@"FlexLayout"]; [self registerViewNode:DoricFlexNode.class withName:@"FlexLayout"];
[self registerViewNode:DoricFlexScrollerNode.class withName:@"FlexScroller"];
} }
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name { - (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {

View File

@ -58,12 +58,6 @@ - (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexCon
- (void)requestLayout { - (void)requestLayout {
[super requestLayout]; [super requestLayout];
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[DoricFlexView class]]) {
continue;
}
[view.doricLayout apply];
}
if (self.view.doricLayout.widthSpec != DoricLayoutFit) { if (self.view.doricLayout.widthSpec != DoricLayoutFit) {
self.view.yoga.width = YGPointValue(self.view.width); self.view.yoga.width = YGPointValue(self.view.width);
} }
@ -73,7 +67,7 @@ - (void)requestLayout {
[self.view.yoga applyLayoutPreservingOrigin:YES]; [self.view.yoga applyLayoutPreservingOrigin:YES];
/// Need layout again. /// Need layout again.
for (UIView *view in self.view.subviews) { for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[DoricFlexView class]]) { if (view.yoga.isEnabled) {
continue; continue;
} }
if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) { if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) {

View File

@ -0,0 +1,26 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Created by pengfei.zhou on 2020/4/11.
//
#import <Foundation/Foundation.h>
#import "DoricGroupNode.h"
@interface DoricFlexScrollerNode : DoricGroupNode <UIScrollView *>
- (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig;
@end

View File

@ -0,0 +1,194 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Created by pengfei.zhou on 2020/4/11.
//
#import "DoricExtensions.h"
#import "DoricFlexScrollerNode.h"
#import "DoricJSDispatcher.h"
#import "DoricScrollableProtocol.h"
#import "DoricRefreshableNode.h"
@interface DoricFlexScrollView : UIScrollView
@end
@implementation DoricFlexScrollView
- (CGSize)sizeThatFits:(CGSize)size {
return [self.yoga intrinsicSize];
}
@end
@interface DoricFlexScrollerNode () <UIScrollViewDelegate>
@property(nonatomic, copy) NSString *onScrollFuncId;
@property(nonatomic, copy) NSString *onScrollEndFuncId;
@property(nonatomic, strong) NSMutableSet <DoricDidScrollBlock> *didScrollBlocks;
@property(nonatomic, strong) DoricJSDispatcher *jsDispatcher;
@end
@implementation DoricFlexScrollerNode
- (UIScrollView *)build {
return [[DoricFlexScrollView new] also:^(UIScrollView *it) {
[it configureLayoutWithBlock:^(YGLayout *layout) {
layout.isEnabled = YES;
layout.overflow = YGOverflowScroll;
}];
it.delegate = self;
it.showsHorizontalScrollIndicator = NO;
it.showsVerticalScrollIndicator = NO;
if (@available(iOS 11, *)) {
it.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}];
}
- (void)initWithSuperNode:(DoricSuperNode *)superNode {
[super initWithSuperNode:superNode];
if ([superNode isKindOfClass:[DoricRefreshableNode class]]) {
self.view.bounces = NO;
}
}
- (void)afterBlended:(NSDictionary *)props {
[super afterBlended:props];
if (props[@"contentOffset"]) {
NSDictionary *prop = props[@"contentOffset"];
self.view.contentOffset = CGPointMake([prop[@"x"] floatValue], [prop[@"y"] floatValue]);
}
}
- (void)requestLayout {
[super requestLayout];
[self.view.yoga applyLayoutPreservingOrigin:YES];
self.view.contentSize = self.view.yoga.intrinsicSize;
/// Need layout again.
for (UIView *view in self.view.subviews) {
if (view.yoga.isEnabled) {
continue;
}
if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) {
continue;
}
view.doricLayout.widthSpec = DoricLayoutJust;
view.doricLayout.heightSpec = DoricLayoutJust;
view.doricLayout.width = view.width;
view.doricLayout.height = view.height;
view.doricLayout.measuredX = view.left;
view.doricLayout.measuredY = view.top;
[view.doricLayout apply];
}
}
- (void)blendView:(UIScrollView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([@"flexConfig" isEqualToString:name]) {
[self blendYoga:view.yoga from:prop];
} else if ([@"onScroll" isEqualToString:name]) {
self.onScrollFuncId = prop;
} else if ([@"onScrollEnd" isEqualToString:name]) {
self.onScrollEndFuncId = prop;
} else {
[super blendView:view forPropName:name propValue:prop];
}
}
- (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig {
[subNode.view configureLayoutWithBlock:^(YGLayout *_Nonnull layout) {
layout.isEnabled = YES;
}];
[self blendYoga:subNode.view.yoga from:flexConfig];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
for (DoricDidScrollBlock block in self.didScrollBlocks) {
block(scrollView);
}
if (self.onScrollFuncId) {
if (!self.jsDispatcher) {
self.jsDispatcher = [DoricJSDispatcher new];
}
__weak typeof(self) __self = self;
[self.jsDispatcher dispatch:^DoricAsyncResult * {
__strong typeof(__self) self = __self;
return [self callJSResponse:self.onScrollFuncId,
@{
@"x": @(self.view.contentOffset.x),
@"y": @(self.view.contentOffset.y),
},
nil];
}];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (self.onScrollEndFuncId) {
[self callJSResponse:self.onScrollEndFuncId,
@{
@"x": @(self.view.contentOffset.x),
@"y": @(self.view.contentOffset.y),
},
nil];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
if (self.onScrollEndFuncId) {
[self callJSResponse:self.onScrollEndFuncId,
@{
@"x": @(self.view.contentOffset.x),
@"y": @(self.view.contentOffset.y),
},
nil];
}
}
}
- (void)scrollTo:(NSDictionary *)params {
BOOL animated = [params[@"animated"] boolValue];
NSDictionary *offsetDic = params[@"offset"];
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];
}
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
if (!_didScrollBlocks) {
_didScrollBlocks = [NSMutableSet new];
}
return _didScrollBlocks;
}
- (void)addDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
[self.didScrollBlocks addObject:didScrollListener];
}
- (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
[self.didScrollBlocks removeObject:didScrollListener];
}
@end

View File

@ -30,6 +30,7 @@
#import "DoricExtensions.h" #import "DoricExtensions.h"
#import "DoricPromise.h" #import "DoricPromise.h"
#import "DoricFlexNode.h" #import "DoricFlexNode.h"
#import "DoricFlexScrollerNode.h"
void DoricAddEllipticArcPath(CGMutablePathRef path, void DoricAddEllipticArcPath(CGMutablePathRef path,
CGPoint origin, CGPoint origin,
@ -266,9 +267,12 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
self.view.hidden = [prop boolValue]; self.view.hidden = [prop boolValue];
self.view.doricLayout.disabled = [prop boolValue]; self.view.doricLayout.disabled = [prop boolValue];
} else if ([name isEqualToString:@"flexConfig"]) { } else if ([name isEqualToString:@"flexConfig"]) {
if ([prop isKindOfClass:[NSDictionary class]] if ([prop isKindOfClass:[NSDictionary class]]) {
&& [self.superNode isKindOfClass:[DoricFlexNode class]]) { if ([self.superNode isKindOfClass:[DoricFlexNode class]]) {
[((DoricFlexNode *) self.superNode) blendSubNode:self flexConfig:prop]; [((DoricFlexNode *) self.superNode) blendSubNode:self flexConfig:prop];
} else if ([self.superNode isKindOfClass:[DoricFlexScrollerNode class]]) {
[((DoricFlexScrollerNode *) self.superNode) blendSubNode:self flexConfig:prop];
}
} }
} else { } else {
DoricLog(@"Blend View error for View Type :%@, prop is %@", self.class, name); DoricLog(@"Blend View error for View Type :%@, prop is %@", self.class, name);

View File

@ -2629,6 +2629,89 @@ function switchView(config) {
return ret; return ret;
} }
var __extends$e = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate$e = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") { r = Reflect.decorate(decorators, target, key, desc); }
else { for (var i = decorators.length - 1; i >= 0; i--) { if (d = decorators[i]) { r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; } } }
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata$e = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(k, v); }
};
var __values$4 = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) { return m.call(o); }
if (o && typeof o.length === "number") { return {
next: function () {
if (o && i >= o.length) { o = void 0; }
return { value: o && o[i++], done: !o };
}
}; }
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
function flexScroller(views, config) {
var e_1, _a;
var ret = new FlexScroller;
ret.layoutConfig = layoutConfig().fit();
try {
for (var views_1 = __values$4(views), views_1_1 = views_1.next(); !views_1_1.done; views_1_1 = views_1.next()) {
var v = views_1_1.value;
ret.addChild(v);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (views_1_1 && !views_1_1.done && (_a = views_1.return)) { _a.call(views_1); }
}
finally { if (e_1) { throw e_1.error; } }
}
if (config) {
for (var key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret);
}
}
return ret;
}
var FlexScroller = /** @class */ (function (_super) {
__extends$e(FlexScroller, _super);
function FlexScroller() {
return _super !== null && _super.apply(this, arguments) || this;
}
FlexScroller.prototype.scrollTo = function (context, offset, animated) {
return this.nativeChannel(context, "scrollTo")({ offset: offset, animated: animated });
};
FlexScroller.prototype.scrollBy = function (context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset: offset, animated: animated });
};
__decorate$e([
Property,
__metadata$e("design:type", Object)
], FlexScroller.prototype, "contentOffset", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScroll", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScrollEnd", void 0);
return FlexScroller;
}(Group));
function modal(context) { function modal(context) {
return { return {
toast: function (msg, gravity) { toast: function (msg, gravity) {
@ -2925,7 +3008,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true }; if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
} }
}; };
var __values$4 = (undefined && undefined.__values) || function(o) { var __values$5 = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) { return m.call(o); } if (m) { return m.call(o); }
if (o && typeof o.length === "number") { return { if (o && typeof o.length === "number") { return {
@ -2962,10 +3045,10 @@ function animate(context) {
return ret; return ret;
} }
try { try {
for (var _c = __values$4(panel_1.allHeadViews()), _d = _c.next(); !_d.done; _d = _c.next()) { for (var _c = __values$5(panel_1.allHeadViews()), _d = _c.next(); !_d.done; _d = _c.next()) {
var map = _d.value; var map = _d.value;
try { try {
for (var _e = (e_2 = void 0, __values$4(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) { for (var _e = (e_2 = void 0, __values$5(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) {
var v = _f.value; var v = _f.value;
if (v.isDirty()) { if (v.isDirty()) {
var model_1 = v.toModel(); var model_1 = v.toModel();
@ -3081,7 +3164,7 @@ function notch(context) {
}; };
} }
var __values$5 = (undefined && undefined.__values) || function(o) { var __values$6 = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) { return m.call(o); } if (m) { return m.call(o); }
if (o && typeof o.length === "number") { return { if (o && typeof o.length === "number") { return {
@ -3112,7 +3195,7 @@ var Observable = /** @class */ (function () {
this.provider.provide(newV); this.provider.provide(newV);
} }
try { try {
for (var _b = __values$5(this.observers), _c = _b.next(); !_c.done; _c = _b.next()) { for (var _b = __values$6(this.observers), _c = _b.next(); !_c.done; _c = _b.next()) {
var observer = _c.value; var observer = _c.value;
observer(newV); observer(newV);
} }
@ -3156,7 +3239,7 @@ var Provider = /** @class */ (function () {
return Provider; return Provider;
}()); }());
var __extends$e = (undefined && undefined.__extends) || (function () { var __extends$f = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) { var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -3197,7 +3280,7 @@ var ViewModel = /** @class */ (function () {
return ViewModel; return ViewModel;
}()); }());
var VMPanel = /** @class */ (function (_super) { var VMPanel = /** @class */ (function (_super) {
__extends$e(VMPanel, _super); __extends$f(VMPanel, _super);
function VMPanel() { function VMPanel() {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
@ -3220,6 +3303,7 @@ exports.CENTER_Y = CENTER_Y;
exports.Color = Color; exports.Color = Color;
exports.Draggable = Draggable; exports.Draggable = Draggable;
exports.FlexLayout = FlexLayout; exports.FlexLayout = FlexLayout;
exports.FlexScroller = FlexScroller;
exports.FlowLayout = FlowLayout; exports.FlowLayout = FlowLayout;
exports.FlowLayoutItem = FlowLayoutItem; exports.FlowLayoutItem = FlowLayoutItem;
exports.Gravity = Gravity; exports.Gravity = Gravity;
@ -3260,6 +3344,7 @@ exports.ViewModel = ViewModel;
exports.animate = animate; exports.animate = animate;
exports.coordinator = coordinator; exports.coordinator = coordinator;
exports.draggable = draggable; exports.draggable = draggable;
exports.flexScroller = flexScroller;
exports.flexlayout = flexlayout; exports.flexlayout = flexlayout;
exports.flowItem = flowItem; exports.flowItem = flowItem;
exports.flowlayout = flowlayout; exports.flowlayout = flowlayout;

View File

@ -1956,6 +1956,49 @@ function switchView(config) {
return ret; return ret;
} }
var __decorate$e = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata$e = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function flexScroller(views, config) {
const ret = new FlexScroller;
ret.layoutConfig = layoutConfig().fit();
for (let v of views) {
ret.addChild(v);
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret);
}
}
return ret;
}
class FlexScroller extends Group {
scrollTo(context, offset, animated) {
return this.nativeChannel(context, "scrollTo")({ offset, animated });
}
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
}
__decorate$e([
Property,
__metadata$e("design:type", Object)
], FlexScroller.prototype, "contentOffset", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScroll", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScrollEnd", void 0);
function modal(context) { function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
@ -2432,6 +2475,7 @@ exports.CENTER_Y = CENTER_Y;
exports.Color = Color; exports.Color = Color;
exports.Draggable = Draggable; exports.Draggable = Draggable;
exports.FlexLayout = FlexLayout; exports.FlexLayout = FlexLayout;
exports.FlexScroller = FlexScroller;
exports.FlowLayout = FlowLayout; exports.FlowLayout = FlowLayout;
exports.FlowLayoutItem = FlowLayoutItem; exports.FlowLayoutItem = FlowLayoutItem;
exports.Gravity = Gravity; exports.Gravity = Gravity;
@ -2472,6 +2516,7 @@ exports.ViewModel = ViewModel;
exports.animate = animate; exports.animate = animate;
exports.coordinator = coordinator; exports.coordinator = coordinator;
exports.draggable = draggable; exports.draggable = draggable;
exports.flexScroller = flexScroller;
exports.flexlayout = flexlayout; exports.flexlayout = flexlayout;
exports.flowItem = flowItem; exports.flowItem = flowItem;
exports.flowlayout = flowlayout; exports.flowlayout = flowlayout;

View File

@ -3415,6 +3415,49 @@ function switchView(config) {
return ret; return ret;
} }
var __decorate$e = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata$e = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function flexScroller(views, config) {
const ret = new FlexScroller;
ret.layoutConfig = layoutConfig().fit();
for (let v of views) {
ret.addChild(v);
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret);
}
}
return ret;
}
class FlexScroller extends Group {
scrollTo(context, offset, animated) {
return this.nativeChannel(context, "scrollTo")({ offset, animated });
}
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
}
__decorate$e([
Property,
__metadata$e("design:type", Object)
], FlexScroller.prototype, "contentOffset", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScroll", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScrollEnd", void 0);
function modal(context) { function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
@ -4026,6 +4069,7 @@ exports.CENTER_Y = CENTER_Y;
exports.Color = Color; exports.Color = Color;
exports.Draggable = Draggable; exports.Draggable = Draggable;
exports.FlexLayout = FlexLayout; exports.FlexLayout = FlexLayout;
exports.FlexScroller = FlexScroller;
exports.FlowLayout = FlowLayout; exports.FlowLayout = FlowLayout;
exports.FlowLayoutItem = FlowLayoutItem; exports.FlowLayoutItem = FlowLayoutItem;
exports.Gravity = Gravity; exports.Gravity = Gravity;
@ -4066,6 +4110,7 @@ exports.ViewModel = ViewModel;
exports.animate = animate; exports.animate = animate;
exports.coordinator = coordinator; exports.coordinator = coordinator;
exports.draggable = draggable; exports.draggable = draggable;
exports.flexScroller = flexScroller;
exports.flexlayout = flexlayout; exports.flexlayout = flexlayout;
exports.flowItem = flowItem; exports.flowItem = flowItem;
exports.flowlayout = flowlayout; exports.flowlayout = flowlayout;

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

@ -88,6 +88,7 @@ declare module 'doric/lib/src/widget/index.widget' {
export * from 'doric/lib/src/widget/nestedSlider'; export * from 'doric/lib/src/widget/nestedSlider';
export * from 'doric/lib/src/widget/draggable'; export * from 'doric/lib/src/widget/draggable';
export * from 'doric/lib/src/widget/switch'; export * from 'doric/lib/src/widget/switch';
export * from 'doric/lib/src/widget/flexScroller';
} }
declare module 'doric/lib/src/native/index.native' { declare module 'doric/lib/src/native/index.native' {
@ -465,7 +466,7 @@ declare module 'doric/lib/src/widget/layouts' {
export function vlayout(views: View[], config?: IVLayout): VLayout; export function vlayout(views: View[], config?: IVLayout): VLayout;
export class FlexLayout extends Group { export class FlexLayout extends Group {
} }
export function flexlayout(views: View[], config: IView): FlexLayout; export function flexlayout(views: View[], config?: IView): FlexLayout;
export {}; export {};
} }
@ -870,6 +871,40 @@ declare module 'doric/lib/src/widget/switch' {
export function switchView(config: ISwitch): Switch; export function switchView(config: ISwitch): Switch;
} }
declare module 'doric/lib/src/widget/flexScroller' {
import { View, IView, Group } from 'doric/lib/src/ui/view';
import { BridgeContext } from 'doric/lib/src/runtime/global';
export function flexScroller(views: View[], config?: IFlexScroller): FlexScroller;
export interface IFlexScroller extends IView {
contentOffset?: {
x: number;
y: number;
};
}
export class FlexScroller extends Group implements IFlexScroller {
contentOffset?: {
x: number;
y: number;
};
onScroll?: (offset: {
x: number;
y: number;
}) => void;
onScrollEnd?: (offset: {
x: number;
y: number;
}) => void;
scrollTo(context: BridgeContext, offset: {
x: number;
y: number;
}, animated?: boolean): Promise<any>;
scrollBy(context: BridgeContext, offset: {
x: number;
y: number;
}, animated?: boolean): Promise<any>;
}
}
declare module 'doric/lib/src/native/modal' { declare module 'doric/lib/src/native/modal' {
import { BridgeContext } from "doric/lib/src/runtime/global"; import { BridgeContext } from "doric/lib/src/runtime/global";
import { Gravity } from "doric/lib/src/util/gravity"; import { Gravity } from "doric/lib/src/util/gravity";

View File

@ -0,0 +1,31 @@
import { View, IView, Group } from '../ui/view';
import { BridgeContext } from '../runtime/global';
export declare function flexScroller(views: View[], config?: IFlexScroller): FlexScroller;
export interface IFlexScroller extends IView {
contentOffset?: {
x: number;
y: number;
};
}
export declare class FlexScroller extends Group implements IFlexScroller {
contentOffset?: {
x: number;
y: number;
};
onScroll?: (offset: {
x: number;
y: number;
}) => void;
onScrollEnd?: (offset: {
x: number;
y: number;
}) => void;
scrollTo(context: BridgeContext, offset: {
x: number;
y: number;
}, animated?: boolean): Promise<any>;
scrollBy(context: BridgeContext, offset: {
x: number;
y: number;
}, animated?: boolean): Promise<any>;
}

View File

@ -0,0 +1,59 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Property, Group } from '../ui/view';
import { layoutConfig } from '../util/layoutconfig';
export function flexScroller(views, config) {
const ret = new FlexScroller;
ret.layoutConfig = layoutConfig().fit();
for (let v of views) {
ret.addChild(v);
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret);
}
}
return ret;
}
export class FlexScroller extends Group {
scrollTo(context, offset, animated) {
return this.nativeChannel(context, "scrollTo")({ offset, animated });
}
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
}
__decorate([
Property,
__metadata("design:type", Object)
], FlexScroller.prototype, "contentOffset", void 0);
__decorate([
Property,
__metadata("design:type", Function)
], FlexScroller.prototype, "onScroll", void 0);
__decorate([
Property,
__metadata("design:type", Function)
], FlexScroller.prototype, "onScrollEnd", void 0);

View File

@ -10,3 +10,4 @@ export * from './input';
export * from './nestedSlider'; export * from './nestedSlider';
export * from './draggable'; export * from './draggable';
export * from './switch'; export * from './switch';
export * from './flexScroller';

View File

@ -25,3 +25,4 @@ export * from './input';
export * from './nestedSlider'; export * from './nestedSlider';
export * from './draggable'; export * from './draggable';
export * from './switch'; export * from './switch';
export * from './flexScroller';

View File

@ -27,5 +27,5 @@ export declare function hlayout(views: View[], config?: IHLayout): HLayout;
export declare function vlayout(views: View[], config?: IVLayout): VLayout; export declare function vlayout(views: View[], config?: IVLayout): VLayout;
export declare class FlexLayout extends Group { export declare class FlexLayout extends Group {
} }
export declare function flexlayout(views: View[], config: IView): FlexLayout; export declare function flexlayout(views: View[], config?: IView): FlexLayout;
export {}; export {};

View File

@ -0,0 +1,56 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { View, IView, Property, Group } from '../ui/view'
import { layoutConfig } from '../util/layoutconfig'
import { BridgeContext } from '../runtime/global'
export function flexScroller(views: View[], config?: IFlexScroller) {
const ret = new FlexScroller
ret.layoutConfig = layoutConfig().fit()
for (let v of views) {
ret.addChild(v)
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
}
return ret
}
export interface IFlexScroller extends IView {
contentOffset?: { x: number, y: number }
}
export class FlexScroller extends Group implements IFlexScroller {
@Property
contentOffset?: { x: number, y: number }
@Property
onScroll?: (offset: { x: number, y: number }) => void
@Property
onScrollEnd?: (offset: { x: number, y: number }) => void
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 })
}
}

View File

@ -24,4 +24,5 @@ export * from './flowlayout'
export * from './input' export * from './input'
export * from './nestedSlider' export * from './nestedSlider'
export * from './draggable' export * from './draggable'
export * from './switch' export * from './switch'
export * from './flexScroller'

View File

@ -98,7 +98,7 @@ export function vlayout(views: View[], config?: IVLayout) {
export class FlexLayout extends Group { export class FlexLayout extends Group {
} }
export function flexlayout(views: View[], config: IView) { export function flexlayout(views: View[], config?: IView) {
const ret = new FlexLayout const ret = new FlexLayout
ret.layoutConfig = layoutConfig().fit() ret.layoutConfig = layoutConfig().fit()
for (let v of views) { for (let v of views) {

View File

@ -3473,6 +3473,49 @@ function switchView(config) {
return ret; return ret;
} }
var __decorate$e = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata$e = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function flexScroller(views, config) {
const ret = new FlexScroller;
ret.layoutConfig = layoutConfig().fit();
for (let v of views) {
ret.addChild(v);
}
if (config) {
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret);
}
}
return ret;
}
class FlexScroller extends Group {
scrollTo(context, offset, animated) {
return this.nativeChannel(context, "scrollTo")({ offset, animated });
}
scrollBy(context, offset, animated) {
return this.nativeChannel(context, "scrollBy")({ offset, animated });
}
}
__decorate$e([
Property,
__metadata$e("design:type", Object)
], FlexScroller.prototype, "contentOffset", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScroll", void 0);
__decorate$e([
Property,
__metadata$e("design:type", Function)
], FlexScroller.prototype, "onScrollEnd", void 0);
function modal(context) { function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
@ -3949,6 +3992,7 @@ exports.CENTER_Y = CENTER_Y;
exports.Color = Color; exports.Color = Color;
exports.Draggable = Draggable; exports.Draggable = Draggable;
exports.FlexLayout = FlexLayout; exports.FlexLayout = FlexLayout;
exports.FlexScroller = FlexScroller;
exports.FlowLayout = FlowLayout; exports.FlowLayout = FlowLayout;
exports.FlowLayoutItem = FlowLayoutItem; exports.FlowLayoutItem = FlowLayoutItem;
exports.Gravity = Gravity; exports.Gravity = Gravity;
@ -3989,6 +4033,7 @@ exports.ViewModel = ViewModel;
exports.animate = animate; exports.animate = animate;
exports.coordinator = coordinator; exports.coordinator = coordinator;
exports.draggable = draggable; exports.draggable = draggable;
exports.flexScroller = flexScroller;
exports.flexlayout = flexlayout; exports.flexlayout = flexlayout;
exports.flowItem = flowItem; exports.flowItem = flowItem;
exports.flowlayout = flowlayout; exports.flowlayout = flowlayout;

File diff suppressed because one or more lines are too long