rename dir
This commit is contained in:
18
doric-iOS/Pod/Classes/Util/Category/NSString+JsonString.h
Normal file
18
doric-iOS/Pod/Classes/Util/Category/NSString+JsonString.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// NSString+JsonString.h
|
||||
// Doric
|
||||
//
|
||||
// Created by Insomnia on 2019/11/7.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSString (JsonString)
|
||||
+ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
23
doric-iOS/Pod/Classes/Util/Category/NSString+JsonString.m
Normal file
23
doric-iOS/Pod/Classes/Util/Category/NSString+JsonString.m
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// NSString+JsonString.m
|
||||
// Doric
|
||||
//
|
||||
// Created by Insomnia on 2019/11/7.
|
||||
//
|
||||
|
||||
#import "NSString+JsonString.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@implementation NSString (JsonString)
|
||||
+ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic {
|
||||
NSError *err;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&err];
|
||||
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
if (err) {
|
||||
DoricLog(NSStringFromSelector(_cmd), @"Convert dictionary to json string failed.");
|
||||
return nil;
|
||||
}
|
||||
return jsonStr;
|
||||
}
|
||||
@end
|
44
doric-iOS/Pod/Classes/Util/DoricAsyncResult.h
Normal file
44
doric-iOS/Pod/Classes/Util/DoricAsyncResult.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricAsyncResult.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
@interface DoricAsyncResult <R> : NSObject
|
||||
@property(nonatomic, strong) void (^resultCallback)(R result);
|
||||
@property(nonatomic, strong) void (^exceptionCallback)(NSException *e);
|
||||
@property(nonatomic, strong) void (^finishCallback)(void);
|
||||
|
||||
- (void)setupResult:(R)result;
|
||||
|
||||
- (void)setupError:(NSException *)exception;
|
||||
|
||||
- (BOOL)hasResult;
|
||||
|
||||
- (R)getResult;
|
||||
|
||||
- (R)waitUntilResult;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
92
doric-iOS/Pod/Classes/Util/DoricAsyncResult.m
Normal file
92
doric-iOS/Pod/Classes/Util/DoricAsyncResult.m
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricAsyncResult.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import "DoricAsyncResult.h"
|
||||
|
||||
@interface DoricAsyncResult ()
|
||||
@property(nonatomic, strong) id result;
|
||||
@end
|
||||
|
||||
@implementation DoricAsyncResult
|
||||
|
||||
- (void)setupResult:(id)result {
|
||||
self.result = result;
|
||||
if (self.resultCallback) {
|
||||
self.resultCallback(result);
|
||||
}
|
||||
if (self.finishCallback) {
|
||||
self.finishCallback();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupError:(NSException *)exception {
|
||||
self.result = exception;
|
||||
if (self.exceptionCallback) {
|
||||
self.exceptionCallback(exception);
|
||||
}
|
||||
if (self.finishCallback) {
|
||||
self.finishCallback();
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)hasResult {
|
||||
return self.result != nil;
|
||||
}
|
||||
|
||||
- (id)getResult {
|
||||
return self.result;
|
||||
}
|
||||
|
||||
- (void)setResultCallback:(void (^)(id))callback {
|
||||
_resultCallback = callback;
|
||||
if (self.result && ![self.result isKindOfClass:[NSException class]]) {
|
||||
callback(self.result);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setExceptionCallback:(void (^)(NSException *))exceptionCallback {
|
||||
_exceptionCallback = exceptionCallback;
|
||||
if ([self.result isKindOfClass:[NSException class]]) {
|
||||
exceptionCallback(self.result);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFinishCallback:(void (^)(void))finishCallback {
|
||||
_finishCallback = finishCallback;
|
||||
if (self.result) {
|
||||
finishCallback();
|
||||
}
|
||||
}
|
||||
|
||||
- (id)waitUntilResult {
|
||||
if (self.result) {
|
||||
return self.result;
|
||||
}
|
||||
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
self.resultCallback = ^(id r) {
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
};
|
||||
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
||||
return self.result;
|
||||
}
|
||||
@end
|
65
doric-iOS/Pod/Classes/Util/DoricConstant.h
Normal file
65
doric-iOS/Pod/Classes/Util/DoricConstant.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricConstant.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
extern NSString *const DORIC_BUNDLE_SANDBOX;
|
||||
extern NSString *const DORIC_BUNDLE_LIB;
|
||||
extern NSString *const DORIC_MODULE_LIB;
|
||||
|
||||
extern NSString *const INJECT_ENVIRONMENT;
|
||||
extern NSString *const INJECT_LOG;
|
||||
extern NSString *const INJECT_REQUIRE;
|
||||
extern NSString *const INJECT_TIMER_SET;
|
||||
extern NSString *const INJECT_TIMER_CLEAR;
|
||||
extern NSString *const INJECT_BRIDGE;
|
||||
extern NSString *const INJECT_EMPTY;
|
||||
|
||||
extern NSString *const TEMPLATE_CONTEXT_CREATE;
|
||||
|
||||
extern NSString *const TEMPLATE_MODULE;
|
||||
|
||||
extern NSString *const TEMPLATE_CONTEXT_DESTROY;
|
||||
|
||||
extern NSString *const GLOBAL_DORIC;
|
||||
|
||||
extern NSString *const DORIC_CONTEXT_RELEASE;
|
||||
|
||||
extern NSString *const DORIC_CONTEXT_INVOKE;
|
||||
|
||||
extern NSString *const DORIC_TIMER_CALLBACK;
|
||||
|
||||
extern NSString *const DORIC_BRIDGE_RESOLVE;
|
||||
|
||||
extern NSString *const DORIC_BRIDGE_REJECT;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_RESPONSE;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_INIT;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_CREATE;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_DESTROY;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_SHOW;
|
||||
|
||||
extern NSString *const DORIC_ENTITY_HIDDEN;
|
83
doric-iOS/Pod/Classes/Util/DoricConstant.m
Normal file
83
doric-iOS/Pod/Classes/Util/DoricConstant.m
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricConstant.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import "DoricConstant.h"
|
||||
|
||||
NSString *const DORIC_BUNDLE_SANDBOX = @"doric-sandbox";
|
||||
NSString *const DORIC_BUNDLE_LIB = @"doric-lib";
|
||||
NSString *const DORIC_MODULE_LIB = @"doric";
|
||||
|
||||
NSString *const INJECT_ENVIRONMENT = @"Environment";
|
||||
|
||||
NSString *const INJECT_LOG = @"nativeLog";
|
||||
NSString *const INJECT_REQUIRE = @"nativeRequire";
|
||||
NSString *const INJECT_TIMER_SET = @"nativeSetTimer";
|
||||
NSString *const INJECT_TIMER_CLEAR = @"nativeClearTimer";
|
||||
NSString *const INJECT_BRIDGE = @"nativeBridge";
|
||||
NSString *const INJECT_EMPTY = @"nativeEmpty";
|
||||
|
||||
NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply("
|
||||
"function(doric,context,Entry,require,exports){" "\n"
|
||||
"%@" "\n"
|
||||
"},doric.jsObtainContext(\"%@\"),["
|
||||
"undefined,"
|
||||
"doric.jsObtainContext(\"%@\"),"
|
||||
"doric.jsObtainEntry(\"%@\"),"
|
||||
"doric.__require__"
|
||||
",{}"
|
||||
"])";
|
||||
|
||||
NSString *const TEMPLATE_MODULE = @"Reflect.apply(doric.jsRegisterModule,this,["
|
||||
"\"%@\","
|
||||
"Reflect.apply(function(__module){"
|
||||
"(function(module,exports,require){" "\n"
|
||||
"%@" "\n"
|
||||
"})(__module,__module.exports,doric.__require__);"
|
||||
"\nreturn __module.exports;"
|
||||
"},this,[{exports:{}}])"
|
||||
"])";
|
||||
|
||||
NSString *const TEMPLATE_CONTEXT_DESTROY = @"doric.jsReleaseContext(\"%@\")";
|
||||
|
||||
NSString *const GLOBAL_DORIC = @"doric";
|
||||
|
||||
NSString *const DORIC_CONTEXT_RELEASE = @"jsReleaseContext";
|
||||
|
||||
NSString *const DORIC_CONTEXT_INVOKE = @"jsCallEntityMethod";
|
||||
|
||||
NSString *const DORIC_TIMER_CALLBACK = @"jsCallbackTimer";
|
||||
|
||||
NSString *const DORIC_BRIDGE_RESOLVE = @"jsCallResolve";
|
||||
|
||||
NSString *const DORIC_BRIDGE_REJECT = @"jsCallReject";
|
||||
|
||||
NSString *const DORIC_ENTITY_RESPONSE = @"__response__";
|
||||
|
||||
NSString *const DORIC_ENTITY_INIT = @"__init__";
|
||||
|
||||
NSString *const DORIC_ENTITY_CREATE = @"__onCreate__";
|
||||
|
||||
NSString *const DORIC_ENTITY_DESTROY = @"__onDestroy__";
|
||||
|
||||
NSString *const DORIC_ENTITY_SHOW = @"__onShow__";
|
||||
|
||||
NSString *const DORIC_ENTITY_HIDDEN = @"__onHidden__";
|
47
doric-iOS/Pod/Classes/Util/DoricExtensions.h
Normal file
47
doric-iOS/Pod/Classes/Util/DoricExtensions.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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/10/23.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface NSObject (Doric)
|
||||
- (id)apply:(id (^)(id it))block;
|
||||
|
||||
- (instancetype)also:(void (^)(id it))block;
|
||||
|
||||
- (void)let:(void (^)(id it))block;
|
||||
@end
|
||||
|
||||
@interface NSArray <ObjectType> (Doric)
|
||||
- (void)forEachIndexed:(void (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
|
||||
|
||||
- (NSArray *)mapIndexed:(id (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
|
||||
|
||||
- (NSArray *)flatMapIndexed:(NSArray *(NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
|
||||
|
||||
- (NSArray *)filterIndexed:(BOOL (NS_NOESCAPE ^)(ObjectType obj, NSUInteger idx))block;
|
||||
|
||||
- (void)forEach:(void (NS_NOESCAPE ^)(ObjectType obj))block;
|
||||
|
||||
- (NSArray *)map:(id (NS_NOESCAPE ^)(ObjectType obj))block;
|
||||
|
||||
- (NSArray *)flatMap:(NSArray *(NS_NOESCAPE ^)(ObjectType obj))block;
|
||||
|
||||
- (NSArray <ObjectType> *)filter:(BOOL (NS_NOESCAPE ^)(ObjectType obj))block;
|
||||
@end
|
102
doric-iOS/Pod/Classes/Util/DoricExtensions.m
Normal file
102
doric-iOS/Pod/Classes/Util/DoricExtensions.m
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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/10/23.
|
||||
//
|
||||
|
||||
#import "DoricExtensions.h"
|
||||
|
||||
@implementation NSObject (Doric)
|
||||
- (id)apply:(id (^)(id it))block {
|
||||
return block(self);
|
||||
}
|
||||
|
||||
- (instancetype)also:(void (^)(id it))block {
|
||||
block(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)let:(void (^)(id it))block {
|
||||
block(self);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSArray (Doric)
|
||||
- (void)forEachIndexed:(void (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
|
||||
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
block(obj, idx);
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSArray *)mapIndexed:(id (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[temp addObject:block(obj, idx)];
|
||||
}];
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
- (NSArray *)flatMapIndexed:(NSArray *(NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[temp addObjectsFromArray:block(obj, idx)];
|
||||
}];
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
- (NSArray *)filterIndexed:(BOOL (NS_NOESCAPE ^)(id obj, NSUInteger idx))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
if (block(obj, idx)) {
|
||||
[temp addObject:obj];
|
||||
}
|
||||
}];
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
- (void)forEach:(void (NS_NOESCAPE ^)(id obj))block {
|
||||
for (id obj in self) {
|
||||
block(obj);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)map:(id (NS_NOESCAPE ^)(id obj))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
for (id obj in self) {
|
||||
[temp addObject:block(obj)];
|
||||
}
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
- (NSArray *)flatMap:(NSArray *(NS_NOESCAPE ^)(id obj))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
for (id obj in self) {
|
||||
[temp addObjectsFromArray:block(obj)];
|
||||
}
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
- (NSArray *)filter:(BOOL (NS_NOESCAPE ^)(id obj))block {
|
||||
NSMutableArray *temp = [NSMutableArray new];
|
||||
for (id obj in self) {
|
||||
if (block(obj)) {
|
||||
[temp addObject:obj];
|
||||
}
|
||||
}
|
||||
return [temp copy];
|
||||
}
|
||||
|
||||
@end
|
24
doric-iOS/Pod/Classes/Util/DoricJSRemoteArgType.h
Normal file
24
doric-iOS/Pod/Classes/Util/DoricJSRemoteArgType.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// DoricJSRemoteArgType.h
|
||||
// Doric
|
||||
//
|
||||
// Created by Insomnia on 2019/11/7.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) {
|
||||
DoricJSRemoteArgTypeNil = 0,
|
||||
DoricJSRemoteArgTypeNumber,
|
||||
DoricJSRemoteArgTypeBool,
|
||||
DoricJSRemoteArgTypeString,
|
||||
DoricJSRemoteArgTypeObject,
|
||||
DoricJSRemoteArgTypeArray,
|
||||
};
|
||||
|
||||
DoricJSRemoteArgType DoricargTypeWithArg(id arg);
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
21
doric-iOS/Pod/Classes/Util/DoricJSRemoteArgType.m
Normal file
21
doric-iOS/Pod/Classes/Util/DoricJSRemoteArgType.m
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// DoricJSRemoteArgType.m
|
||||
// Doric
|
||||
//
|
||||
// Created by Insomnia on 2019/11/7.
|
||||
//
|
||||
|
||||
#import "DoricJSRemoteArgType.h"
|
||||
DoricJSRemoteArgType DoricargTypeWithArg(id arg) {
|
||||
DoricJSRemoteArgType type = DoricJSRemoteArgTypeNil;
|
||||
if ([arg isKindOfClass:[NSNumber class]]) {
|
||||
type = DoricJSRemoteArgTypeNumber;
|
||||
}else if ([arg isKindOfClass:[NSString class]]) {
|
||||
type = DoricJSRemoteArgTypeString;
|
||||
}else if ([arg isKindOfClass:[NSDictionary class]]) {
|
||||
type = DoricJSRemoteArgTypeObject;
|
||||
}else if ([arg isKindOfClass:[NSMutableArray class]]) {
|
||||
type = DoricJSRemoteArgTypeArray;
|
||||
}
|
||||
return type;
|
||||
}
|
42
doric-iOS/Pod/Classes/Util/DoricUtil.h
Normal file
42
doric-iOS/Pod/Classes/Util/DoricUtil.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricUtil.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricLayouts.h"
|
||||
|
||||
void DoricLog(NSString *_Nonnull format, ...);
|
||||
|
||||
UIColor *_Nonnull DoricColor(NSNumber *_Nonnull number);
|
||||
|
||||
NSBundle *_Nonnull DoricBundle(void);
|
||||
|
||||
#ifndef DC_LOCK
|
||||
#define DC_LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||
#endif
|
||||
|
||||
#ifndef DC_UNLOCK
|
||||
#define DC_UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
#endif
|
||||
|
||||
void ShowToast(NSString *_Nonnull text, DoricGravity gravity);
|
||||
|
||||
UIImage *_Nonnull UIImageWithColor(UIColor * _Nonnull color);
|
88
doric-iOS/Pod/Classes/Util/DoricUtil.m
Normal file
88
doric-iOS/Pod/Classes/Util/DoricUtil.m
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
//
|
||||
// DoricUtil.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricContext.h"
|
||||
#import "UIView+Doric.h"
|
||||
|
||||
void DoricLog(NSString *_Nonnull format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
NSLogv([NSString stringWithFormat:@"Doric:%@", format], args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
UIColor *DoricColor(NSNumber *number) {
|
||||
CGFloat r, g, b, a;
|
||||
long colorValue = [number longValue];
|
||||
a = ((colorValue >> 24) & 0xff) / 255.0f;
|
||||
r = ((colorValue >> 16) & 0xff) / 255.0f;
|
||||
g = ((colorValue >> 8) & 0xff) / 255.0f;
|
||||
b = ((colorValue >> 0) & 0xff) / 255.0f;
|
||||
return [UIColor colorWithRed:r green:g blue:b alpha:a];
|
||||
}
|
||||
|
||||
NSBundle *DoricBundle() {
|
||||
NSBundle *bundle = [NSBundle bundleForClass:[DoricContext class]];
|
||||
NSURL *url = [bundle URLForResource:@"Doric" withExtension:@"bundle"];
|
||||
return [NSBundle bundleWithURL:url];
|
||||
}
|
||||
|
||||
|
||||
void ShowToast(NSString *text, DoricGravity gravity) {
|
||||
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
label.font = [UIFont systemFontOfSize:20.f];
|
||||
label.text = text;
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.layer.masksToBounds = YES;
|
||||
label.backgroundColor = [UIColor grayColor];
|
||||
label.textColor = [UIColor whiteColor];
|
||||
[label sizeToFit];
|
||||
label.width += 30;
|
||||
label.height += 10;
|
||||
label.layer.cornerRadius = label.height / 2;
|
||||
label.centerX = superView.width / 2;
|
||||
if ((gravity & BOTTOM) == BOTTOM) {
|
||||
label.bottom = superView.height - 20;
|
||||
} else if ((gravity & TOP) == TOP) {
|
||||
label.top = 108;
|
||||
} else {
|
||||
label.centerY = (superView.height - 88) / 2;
|
||||
}
|
||||
|
||||
[superView addSubview:label];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[label removeFromSuperview];
|
||||
});
|
||||
}
|
||||
|
||||
UIImage *UIImageWithColor(UIColor *color) {
|
||||
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
UIGraphicsBeginImageContext(rect.size);
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetFillColorWithColor(context, [color CGColor]);
|
||||
CGContextFillRect(context, rect);
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return image;
|
||||
}
|
Reference in New Issue
Block a user