feat:iOS implement coordinator plugin
This commit is contained in:
parent
630ec51504
commit
6bf61b3769
@ -180,6 +180,10 @@ public class CoordinatorPlugin extends DoricJavaPlugin {
|
|||||||
viewNode.setWidth(value);
|
viewNode.setWidth(value);
|
||||||
} else if ("height".equals(name)) {
|
} else if ("height".equals(name)) {
|
||||||
viewNode.setHeight(value);
|
viewNode.setHeight(value);
|
||||||
|
} else if ("x".equals(name)) {
|
||||||
|
viewNode.setX(value);
|
||||||
|
} else if ("y".equals(name)) {
|
||||||
|
viewNode.setY(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, Image } from "doric";
|
import { Group, Panel, coordinator, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, Image } from "doric";
|
||||||
import { colors, label } from "./utils";
|
import { colors, label } from "./utils";
|
||||||
import { img_base64 } from "./image_base64";
|
import { img_base64 } from "./image_base64";
|
||||||
const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg'
|
const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg'
|
||||||
@ -43,12 +43,15 @@ class ImageDemo extends Panel {
|
|||||||
label('WebP'),
|
label('WebP'),
|
||||||
imageView = image({
|
imageView = image({
|
||||||
imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp",
|
imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp",
|
||||||
loadCallback: (ret) => {
|
layoutConfig: layoutConfig().just(),
|
||||||
if (ret) {
|
width: 200,
|
||||||
imageView.width = ret.width
|
height: 200,
|
||||||
imageView.height = ret.height
|
// loadCallback: (ret) => {
|
||||||
}
|
// if (ret) {
|
||||||
}
|
// imageView.width = ret.width
|
||||||
|
// imageView.height = ret.height
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}),
|
}),
|
||||||
label('ScaleToFill'),
|
label('ScaleToFill'),
|
||||||
image({
|
image({
|
||||||
@ -110,6 +113,20 @@ class ImageDemo extends Panel {
|
|||||||
{
|
{
|
||||||
layoutConfig: layoutConfig().most(),
|
layoutConfig: layoutConfig().most(),
|
||||||
}
|
}
|
||||||
).in(rootView)
|
).also(it => {
|
||||||
|
coordinator(context).verticalScrolling({
|
||||||
|
scrollable: it,
|
||||||
|
scrollRange: {
|
||||||
|
start: 0,
|
||||||
|
end: 100,
|
||||||
|
},
|
||||||
|
target: "NavBar",
|
||||||
|
changing: {
|
||||||
|
name: "backgroundColor",
|
||||||
|
start: Color.WHITE,
|
||||||
|
end: Color.RED,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).in(rootView)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,4 +29,3 @@
|
|||||||
#import "DoricLibrary.h"
|
#import "DoricLibrary.h"
|
||||||
#import "DoricNativePlugin.h"
|
#import "DoricNativePlugin.h"
|
||||||
#import "DoricMonitorProtocol.h"
|
#import "DoricMonitorProtocol.h"
|
||||||
#import "DoricScrollViewDelegate.h"
|
|
@ -49,6 +49,7 @@
|
|||||||
#import "DoricNotificationPlugin.h"
|
#import "DoricNotificationPlugin.h"
|
||||||
#import "DoricStatusBarPlugin.h"
|
#import "DoricStatusBarPlugin.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
|
#import "DoricCoordinatorPlugin.h"
|
||||||
|
|
||||||
@interface DoricLibraries : NSObject
|
@interface DoricLibraries : NSObject
|
||||||
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
||||||
@ -130,6 +131,7 @@ - (void)innerRegister {
|
|||||||
[self registerNativePlugin:DoricAnimatePlugin.class withName:@"animate"];
|
[self registerNativePlugin:DoricAnimatePlugin.class withName:@"animate"];
|
||||||
[self registerNativePlugin:DoricNotificationPlugin.class withName:@"notification"];
|
[self registerNativePlugin:DoricNotificationPlugin.class withName:@"notification"];
|
||||||
[self registerNativePlugin:DoricStatusBarPlugin.class withName:@"statusbar"];
|
[self registerNativePlugin:DoricStatusBarPlugin.class withName:@"statusbar"];
|
||||||
|
[self registerNativePlugin:DoricCoordinatorPlugin.class withName:@"coordinator"];
|
||||||
|
|
||||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||||
|
10
doric-iOS/Pod/Classes/DoricScrollableProtocol.h
Normal file
10
doric-iOS/Pod/Classes/DoricScrollableProtocol.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2020/2/13.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricScrollableProtocol.h"
|
||||||
|
|
||||||
|
@protocol DoricScrollableProtocol <NSObject>
|
||||||
|
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||||
|
@end
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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 2019/11/29.
|
// Created by pengfei.zhou on 2019/11/29.
|
||||||
//
|
//
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* 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 2019/11/29.
|
// Created by pengfei.zhou on 2019/11/29.
|
||||||
//
|
//
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricNativePlugin.h"
|
||||||
|
|
||||||
@protocol DoricScrollViewDelegate <NSObject>
|
@interface DoricCoordinatorPlugin : DoricNativePlugin
|
||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
|
|
||||||
@end
|
@end
|
133
doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m
Normal file
133
doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* 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/2/13.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricCoordinatorPlugin.h"
|
||||||
|
#import "DoricSuperNode.h"
|
||||||
|
#import "DoricScrollableProtocol.h"
|
||||||
|
#import "DoricUtil.h"
|
||||||
|
|
||||||
|
@implementation DoricCoordinatorPlugin
|
||||||
|
- (void)ready:(id)param withPromise:(DoricPromise *)promise {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[promise resolve:nil];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
NSArray <NSString *> *scrollableIds = params[@"scrollable"];
|
||||||
|
DoricViewNode *scrollNode = nil;
|
||||||
|
for (NSString *value in scrollableIds) {
|
||||||
|
if (!scrollNode) {
|
||||||
|
scrollNode = [self.doricContext targetViewNode:value];
|
||||||
|
} else {
|
||||||
|
if ([scrollNode isKindOfClass:[DoricSuperNode class]]) {
|
||||||
|
scrollNode = [((DoricSuperNode *) scrollNode) subNodeWithViewId:value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!scrollNode) {
|
||||||
|
[promise reject:@"Cannot find scrollable view"];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSDictionary *scrollRange = params[@"scrollRange"];
|
||||||
|
CGFloat startAnchor = [scrollRange[@"start"] floatValue];
|
||||||
|
CGFloat endAnchor = [scrollRange[@"end"] floatValue];
|
||||||
|
id target = params[@"target"];
|
||||||
|
BOOL isNavBar = false;
|
||||||
|
DoricViewNode *targetNode = nil;
|
||||||
|
if ([target isKindOfClass:[NSString class]] && [target isEqualToString:@"NavBar"]) {
|
||||||
|
isNavBar = true;
|
||||||
|
} else {
|
||||||
|
for (NSString *value in target) {
|
||||||
|
if (!targetNode) {
|
||||||
|
targetNode = [self.doricContext targetViewNode:value];
|
||||||
|
} else {
|
||||||
|
if ([targetNode isKindOfClass:[DoricSuperNode class]]) {
|
||||||
|
targetNode = [((DoricSuperNode *) targetNode) subNodeWithViewId:value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!targetNode) {
|
||||||
|
[promise reject:@"Cannot find target view"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NSDictionary *changing = params[@"changing"];
|
||||||
|
NSString *name = changing[@"name"];
|
||||||
|
NSNumber *changingStart = changing[@"start"];
|
||||||
|
NSNumber *changingEnd = changing[@"end"];
|
||||||
|
if ([scrollNode conformsToProtocol:@protocol(DoricScrollableProtocol)]) {
|
||||||
|
((id <DoricScrollableProtocol>) scrollNode).didScrollListener = ^(UIScrollView *scrollView) {
|
||||||
|
CGFloat scrollY = scrollView.contentOffset.y;
|
||||||
|
if (scrollY <= startAnchor) {
|
||||||
|
[self setValue:targetNode isNavBar:isNavBar name:name value:changingStart];
|
||||||
|
} else if (scrollY >= endAnchor) {
|
||||||
|
[self setValue:targetNode isNavBar:isNavBar name:name value:changingEnd];
|
||||||
|
} else {
|
||||||
|
CGFloat range = MAX(1, endAnchor - startAnchor);
|
||||||
|
CGFloat offset = scrollY - startAnchor;
|
||||||
|
CGFloat rate = offset / range;
|
||||||
|
id value;
|
||||||
|
if ([@"backgroundColor" isEqualToString:name]) {
|
||||||
|
UIColor *startColor = DoricColor(changingStart);
|
||||||
|
UIColor *endColor = DoricColor(changingEnd);
|
||||||
|
CGFloat startR, startG, startB, startA;
|
||||||
|
[startColor getRed:&startR green:&startG blue:&startB alpha:&startA];
|
||||||
|
CGFloat endR, endG, endB, endA;
|
||||||
|
[endColor getRed:&endR green:&endG blue:&endB alpha:&endA];
|
||||||
|
value = [UIColor colorWithRed:startR + (endR - startR) * rate
|
||||||
|
green:startG + (endG - startG) * rate
|
||||||
|
blue:startB + (endB - startB) * rate
|
||||||
|
alpha:startA + (endA - startA) * rate];
|
||||||
|
} else {
|
||||||
|
value = @([changingStart floatValue] + ([changingEnd floatValue] - [changingStart floatValue]) * rate);
|
||||||
|
}
|
||||||
|
[self setValue:targetNode isNavBar:isNavBar name:name value:value];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
[promise reject:@"Scroller type error"];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValue:(DoricViewNode *)viewNode isNavBar:(BOOL)isNavBar name:(NSString *)name value:(id)value {
|
||||||
|
if ([@"backgroundColor" isEqualToString:name]) {
|
||||||
|
if ([value isKindOfClass:[NSNumber class]]) {
|
||||||
|
value = DoricColor(value);
|
||||||
|
}
|
||||||
|
if (isNavBar) {
|
||||||
|
[self.doricContext.navBar doric_navBar_setBackgroundColor:value];
|
||||||
|
} else {
|
||||||
|
viewNode.view.backgroundColor = value;
|
||||||
|
}
|
||||||
|
} else if ([@"width" isEqualToString:name]) {
|
||||||
|
viewNode.view.width = [value floatValue];
|
||||||
|
} else if ([@"height" isEqualToString:name]) {
|
||||||
|
viewNode.view.height = [value floatValue];
|
||||||
|
} else if ([@"x" isEqualToString:name]) {
|
||||||
|
viewNode.view.left = [value floatValue];
|
||||||
|
} else if ([@"y" isEqualToString:name]) {
|
||||||
|
viewNode.view.top = [value floatValue];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
#import "DoricScrollViewDelegate.h"
|
#import "DoricScrollableProtocol.h"
|
||||||
|
|
||||||
@interface DoricFlowLayoutNode : DoricSuperNode<UICollectionView *>
|
@interface DoricFlowLayoutNode : DoricSuperNode<UICollectionView *> <DoricScrollableProtocol>
|
||||||
@property(nonatomic, weak, nullable) id <DoricScrollViewDelegate> delegate;
|
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||||
@end
|
@end
|
@ -370,6 +370,8 @@ - (NSInteger)doricFlowLayoutColumnCount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||||
[self.delegate scrollViewDidScroll:scrollView];
|
if (self.didScrollListener) {
|
||||||
|
self.didScrollListener(scrollView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
#import "DoricScrollViewDelegate.h"
|
#import "DoricScrollableProtocol.h"
|
||||||
|
|
||||||
@interface DoricListNode : DoricSuperNode<UITableView *>
|
@interface DoricListNode : DoricSuperNode<UITableView *> <DoricScrollableProtocol>
|
||||||
@property(nonatomic, weak, nullable) id <DoricScrollViewDelegate> delegate;
|
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||||
@end
|
@end
|
@ -250,6 +250,8 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||||
[self.delegate scrollViewDidScroll:scrollView];
|
if (self.didScrollListener) {
|
||||||
|
self.didScrollListener(scrollView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -21,12 +21,12 @@
|
|||||||
//
|
//
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
#import "DoricScrollViewDelegate.h"
|
#import "DoricScrollableProtocol.h"
|
||||||
|
|
||||||
@interface DoricScrollView : UIScrollView
|
@interface DoricScrollView : UIScrollView
|
||||||
@property(nonatomic, strong) UIView *contentView;
|
@property(nonatomic, strong) UIView *contentView;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricScrollerNode : DoricSuperNode<DoricScrollView *>
|
@interface DoricScrollerNode : DoricSuperNode<DoricScrollView *> <DoricScrollableProtocol>
|
||||||
@property(nonatomic, weak, nullable) id <DoricScrollViewDelegate> delegate;
|
@property(nonatomic, strong, nullable) void (^didScrollListener)(UIScrollView *__nonnull scrollView);
|
||||||
@end
|
@end
|
@ -124,7 +124,10 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||||
[self.delegate scrollViewDidScroll:scrollView];
|
if (self.didScrollListener) {
|
||||||
|
self.didScrollListener(scrollView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user