feat:add switch for Android and iOS
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
#import "DoricStatusBarPlugin.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricCoordinatorPlugin.h"
|
||||
#import "DoricSwitchNode.h"
|
||||
|
||||
@interface DoricLibraries : NSObject
|
||||
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
||||
@@ -149,6 +150,7 @@ - (void)innerRegister {
|
||||
[self registerViewNode:DoricNestedSliderNode.class withName:@"NestedSlider"];
|
||||
[self registerViewNode:DoricInputNode.class withName:@"Input"];
|
||||
[self registerViewNode:DoricDraggableNode.class withName:@"Draggable"];
|
||||
[self registerViewNode:DoricSwitchNode.class withName:@"Switch"];
|
||||
}
|
||||
|
||||
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
||||
|
24
doric-iOS/Pod/Classes/Shader/DoricSwitchNode.h
Normal file
24
doric-iOS/Pod/Classes/Shader/DoricSwitchNode.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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/3/12.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricViewNode.h"
|
||||
|
||||
@interface DoricSwitchNode : DoricViewNode <UISwitch *>
|
||||
@end
|
73
doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m
Normal file
73
doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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/3/12.
|
||||
//
|
||||
|
||||
#import "DoricSwitchNode.h"
|
||||
#import "DoricExtensions.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@interface DoricSwitchNode ()
|
||||
@property(nonatomic, copy) NSString *onSwitchFuncId;
|
||||
@end
|
||||
|
||||
@implementation DoricSwitchNode
|
||||
- (UISwitch *)build {
|
||||
return [[UISwitch new] also:^(UISwitch *it) {
|
||||
[it addTarget:self action:@selector(onSwitch) forControlEvents:UIControlEventValueChanged];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)onSwitch {
|
||||
if (self.onSwitchFuncId.length > 0) {
|
||||
[self callJSResponse:self.onSwitchFuncId, @(self.view.isOn), nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
[self.view also:^(UISwitch *it) {
|
||||
it.layer.cornerRadius = it.bounds.size.height / 2;
|
||||
it.layer.masksToBounds = YES;
|
||||
it.clipsToBounds = NO;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)blendView:(UISwitch *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
if ([@"state" isEqualToString:name]) {
|
||||
view.on = [prop boolValue];
|
||||
} else if ([@"onSwitch" isEqualToString:name]) {
|
||||
self.onSwitchFuncId = prop;
|
||||
} else if ([@"offTintColor" isEqualToString:name]) {
|
||||
UIColor *color = DoricColor(prop);
|
||||
view.tintColor = color;
|
||||
view.backgroundColor = color;
|
||||
} else if ([@"onTintColor" isEqualToString:name]) {
|
||||
UIColor *color = DoricColor(prop);
|
||||
view.onTintColor = color;
|
||||
} else if ([@"thumbTintColor" isEqualToString:name]) {
|
||||
UIColor *color = DoricColor(prop);
|
||||
view.thumbTintColor = color;
|
||||
} else {
|
||||
[super blendView:view forPropName:name propValue:prop];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSNumber *)getState {
|
||||
return @(self.view.isOn);
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user