Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Remove unused options. (#1986)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and doumafang committed Jan 2, 2019
1 parent 8ffcb75 commit 5f162ca
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 137 deletions.
5 changes: 1 addition & 4 deletions ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
if (attributes[@"quality"]) {
_imageQuality = [WXConvert WXImageQuality:attributes[@"quality"]];
}
id<WXConfigCenterProtocol> configCenter = [WXSDKEngine handlerForProtocol:@protocol(WXConfigCenterProtocol)];

_downloadImageWithURL = YES;
if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
_downloadImageWithURL = [[configCenter configForKey:@"iOS_weex_ext_config.downloadImageWithURL" defaultValue:@(YES) isDefault:NULL] boolValue];
}
if (attributes[@"compositing"]) {
_downloadImageWithURL = [WXConvert BOOL:attributes[@"compositing"]];
}
Expand Down
1 change: 0 additions & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@interface WXTextComponent : WXComponent
@property (atomic, strong) NSString *text;

+ (void)setRenderUsingCoreText:(BOOL)usingCoreText;
- (BOOL)useCoreText;

@end
22 changes: 3 additions & 19 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ - (NSString *)accessibilityLabel

@end

static BOOL textRenderUsingCoreText = YES;

NSString *const WXTextTruncationToken = @"\u2026";
CGFloat WXTextDefaultLineThroughWidth = 1.2;
static NSString *const WXTextTruncationToken = @"\u2026";
static CGFloat WXTextDefaultLineThroughWidth = 1.2;

@interface WXTextComponent()
@property (nonatomic, strong) NSString *useCoreTextAttr;
Expand Down Expand Up @@ -155,16 +153,6 @@ @implementation WXTextComponent
BOOL _enableCopy;
}

+ (void)setRenderUsingCoreText:(BOOL)usingCoreText
{
textRenderUsingCoreText = usingCoreText;
}

+ (BOOL)textRenderUsingCoreText
{
return textRenderUsingCoreText;
}

- (instancetype)initWithRef:(NSString *)ref
type:(NSString *)type
styles:(NSDictionary *)styles
Expand Down Expand Up @@ -202,11 +190,7 @@ - (BOOL)useCoreText
if ([_useCoreTextAttr isEqualToString:@"false"]) {
return NO;
}

if ([WXTextComponent textRenderUsingCoreText]) {
return YES;
}
return NO;
return YES;
}

- (void)dealloc
Expand Down
6 changes: 0 additions & 6 deletions ios/sdk/WeexSDK/Sources/Model/WXComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
* under the License.
*/

/**
* def : use weex_flex_engin
* ndef: use yoga
**/


#import <Foundation/Foundation.h>
#import "WXType.h"

Expand Down
11 changes: 1 addition & 10 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,7 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString
- (BOOL)_handleConfigCenter
{
id configCenter = [WXSDKEngine handlerForProtocol:@protocol(WXConfigCenterProtocol)];
if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
BOOL useCoreText = [[configCenter configForKey:@"iOS_weex_ext_config.text_render_useCoreText" defaultValue:@YES isDefault:NULL] boolValue];
[WXTextComponent setRenderUsingCoreText:useCoreText];

BOOL unregisterFontWhenCollision = [[configCenter configForKey:@"iOS_weex_ext_config.unregisterFontWhenCollision" defaultValue:@NO isDefault:NULL] boolValue];
[WXUtility setUnregisterFontWhenCollision:unregisterFontWhenCollision];

BOOL useJSCApiForCreateInstance = [[configCenter configForKey:@"iOS_weex_ext_config.useJSCApiForCreateInstance" defaultValue:@(YES) isDefault:NULL] boolValue];
[WXUtility setUseJSCApiForCreateInstance:useJSCApiForCreateInstance];

if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
BOOL enableRTLLayoutDirection = [[configCenter configForKey:@"iOS_weex_ext_config.enableRTLLayoutDirection" defaultValue:@(YES) isDefault:NULL] boolValue];
[WXUtility setEnableRTLLayoutDirection:enableRTLLayoutDirection];
}
Expand Down
6 changes: 0 additions & 6 deletions ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,6 @@ BOOL WXFloatGreaterThanWithPrecision(CGFloat a,CGFloat b,double precision);
*/
+ (NSData *_Nonnull)base64DictToData:(NSDictionary *_Nullable)base64Dict;

+ (void)setUnregisterFontWhenCollision:(BOOL)value;

+ (void)setUseJSCApiForCreateInstance:(BOOL)value;

+ (BOOL)useJSCApiForCreateInstance;

+ (void)setEnableRTLLayoutDirection:(BOOL)value;

+ (BOOL)enableRTLLayoutDirection;
Expand Down
137 changes: 46 additions & 91 deletions ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#define KEY_PASSWORD @"com.taobao.Weex.123456"
#define KEY_USERNAME_PASSWORD @"com.taobao.Weex.weex123456"

static BOOL unregisterFontWhenCollision = NO;
static BOOL useJSCApiForCreateInstance = YES;
static BOOL enableRTLLayoutDirection = YES;

void WXPerformBlockOnMainThread(void (^ _Nonnull block)(void))
Expand Down Expand Up @@ -140,21 +138,6 @@ CGFloat WXFloorPixelValue(CGFloat value)

@implementation WXUtility

+ (void)setUnregisterFontWhenCollision:(BOOL)value
{
unregisterFontWhenCollision = value;
}

+ (void)setUseJSCApiForCreateInstance:(BOOL)value
{
useJSCApiForCreateInstance = value;
}

+ (BOOL)useJSCApiForCreateInstance
{
return useJSCApiForCreateInstance;
}

+ (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread
{
if (!thread || !block) return;
Expand Down Expand Up @@ -525,37 +508,14 @@ + (UIFont *)fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL(fontURL);
if (fontDataProvider) {
CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
if (unregisterFontWhenCollision) {
CFErrorRef error = nil;
CTFontManagerRegisterGraphicsFont(newFont, &error);
// the same font family, remove it and register new one.
if (error) {
CTFontManagerUnregisterGraphicsFont(newFont, NULL);
CTFontManagerRegisterGraphicsFont(newFont, NULL);
CFRelease(error);
}
}
else {
CTFontManagerRegisterGraphicsFont(newFont, NULL);
}
CTFontManagerRegisterGraphicsFont(newFont, NULL);
fontFamily = (__bridge_transfer NSString*)CGFontCopyPostScriptName(newFont);
CGFontRelease(newFont);
CFRelease(fontURL);
CFRelease(fontDataProvider);
}
} else {
if (unregisterFontWhenCollision) {
CFErrorRef error = nil;
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error);
if (error) {
CTFontManagerUnregisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
CFRelease(error);
}
}
else {
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
}
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
NSArray *descriptors = (__bridge_transfer NSArray *)CTFontManagerCreateFontDescriptorsFromURL(fontURL);
// length of descriptors here will be only one.
for (UIFontDescriptor *desc in descriptors) {
Expand Down Expand Up @@ -1026,63 +986,58 @@ + (long) getUnixFixTimeMillis

NSMutableArray* allKeys = nil;

if ([self useJSCApiForCreateInstance]) {
JSContextRef contextRef = jsvalue.context.JSGlobalContextRef;
if (![jsvalue isObject]) {
WXAssert(NO, @"Invalid jsvalue for property enumeration.");
return nil;
}
JSValueRef jsException = NULL;
JSObjectRef instanceContextObjectRef = JSValueToObject(contextRef, jsvalue.JSValueRef, &jsException);
if (jsException != NULL) {
WXLogError(@"JSValueToObject Exception during create instance.");
}
BOOL somethingWrong = NO;
if (instanceContextObjectRef != NULL) {
JSPropertyNameArrayRef allKeyRefs = JSObjectCopyPropertyNames(contextRef, instanceContextObjectRef);
size_t keyCount = JSPropertyNameArrayGetCount(allKeyRefs);

allKeys = [[NSMutableArray alloc] initWithCapacity:keyCount];
for (size_t i = 0; i < keyCount; i ++) {
JSStringRef nameRef = JSPropertyNameArrayGetNameAtIndex(allKeyRefs, i);
size_t len = JSStringGetMaximumUTF8CStringSize(nameRef);
if (len > 1024) {
somethingWrong = YES;
break;
}
char* buf = (char*)malloc(len + 5);
if (buf == NULL) {
somethingWrong = YES;
break;
}
bzero(buf, len + 5);
if (JSStringGetUTF8CString(nameRef, buf, len + 5) > 0) {
NSString* keyString = [NSString stringWithUTF8String:buf];
if ([keyString length] == 0) {
somethingWrong = YES;
free(buf);
break;
}
[allKeys addObject:keyString];
}
else {
JSContextRef contextRef = jsvalue.context.JSGlobalContextRef;
if (![jsvalue isObject]) {
WXAssert(NO, @"Invalid jsvalue for property enumeration.");
return nil;
}
JSValueRef jsException = NULL;
JSObjectRef instanceContextObjectRef = JSValueToObject(contextRef, jsvalue.JSValueRef, &jsException);
if (jsException != NULL) {
WXLogError(@"JSValueToObject Exception during create instance.");
}
BOOL somethingWrong = NO;
if (instanceContextObjectRef != NULL) {
JSPropertyNameArrayRef allKeyRefs = JSObjectCopyPropertyNames(contextRef, instanceContextObjectRef);
size_t keyCount = JSPropertyNameArrayGetCount(allKeyRefs);

allKeys = [[NSMutableArray alloc] initWithCapacity:keyCount];
for (size_t i = 0; i < keyCount; i ++) {
JSStringRef nameRef = JSPropertyNameArrayGetNameAtIndex(allKeyRefs, i);
size_t len = JSStringGetMaximumUTF8CStringSize(nameRef);
if (len > 1024) {
somethingWrong = YES;
break;
}
char* buf = (char*)malloc(len + 5);
if (buf == NULL) {
somethingWrong = YES;
break;
}
bzero(buf, len + 5);
if (JSStringGetUTF8CString(nameRef, buf, len + 5) > 0) {
NSString* keyString = [NSString stringWithUTF8String:buf];
if ([keyString length] == 0) {
somethingWrong = YES;
free(buf);
break;
}
[allKeys addObject:keyString];
}
else {
somethingWrong = YES;
free(buf);
break;
}
JSPropertyNameArrayRelease(allKeyRefs);
} else {
somethingWrong = YES;
}

if (somethingWrong) {
// may contain retain-cycle.
allKeys = (NSMutableArray*)[[jsvalue toDictionary] allKeys];
free(buf);
}
JSPropertyNameArrayRelease(allKeyRefs);
} else {
somethingWrong = YES;
}
else {

if (somethingWrong) {
// may contain retain-cycle.
allKeys = (NSMutableArray*)[[jsvalue toDictionary] allKeys];
}

Expand Down

0 comments on commit 5f162ca

Please sign in to comment.