[iOS] Add switch for dark theme support.
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index a0af7d7..e3341d1 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -103,7 +103,13 @@
{
self = [super init];
if (self) {
- self.themeName = [WXUtility isSystemInDarkTheme] ? @"dark" : @"light";
+ if ([WXUtility isDarkThemeSupportEnabled]) {
+ self.themeName = [WXUtility isSystemInDarkTheme] ? @"dark" : @"light";
+ }
+ else {
+ self.themeName = @"light";
+ }
+
_renderType = renderType;
_appearState = YES;
@@ -604,6 +610,9 @@
BOOL useMRCForInvalidJSONObject = [[configCenter configForKey:@"iOS_weex_ext_config.useMRCForInvalidJSONObject" defaultValue:@(YES) isDefault:NULL] boolValue];
BOOL alwaysUseMRCForObjectToWeexCore = [[configCenter configForKey:@"iOS_weex_ext_config.alwaysUseMRC" defaultValue:@(NO) isDefault:NULL] boolValue];
ConvertSwitches(isIOS13, useMRCForInvalidJSONObject, alwaysUseMRCForObjectToWeexCore);
+
+ BOOL isDarkThemeSupportEnabled = [[configCenter configForKey:@"iOS_weex_ext_config.supportDarkTheme" defaultValue:@(YES) isDefault:NULL] boolValue];
+ [WXUtility setDarkThemeSupportEnable:isDarkThemeSupportEnabled];
}
else {
BOOL isIOS13 = [[[UIDevice currentDevice] systemVersion] integerValue] == 13;
@@ -1193,6 +1202,11 @@
- (void)setCurrentThemeName:(NSString*)name
{
+ if (![WXUtility isDarkThemeSupportEnabled]) {
+ self.themeName = @"light";
+ return;
+ }
+
if (name && ![name isEqualToString:self.themeName]) {
self.themeName = name;
@@ -1229,6 +1243,10 @@
- (UIColor*)chooseColor:(UIColor*)originalColor darkThemeColor:(UIColor*)darkColor invert:(BOOL)invert scene:(WXColorScene)scene
{
+ if (![WXUtility isDarkThemeSupportEnabled]) {
+ return originalColor;
+ }
+
if ([self isDarkTheme]) {
if (darkColor) {
return darkColor;
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
index 4addab0..15cb8c7 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
@@ -510,10 +510,20 @@
*/
+ (NSData *_Nonnull)base64DictToData:(NSDictionary *_Nullable)base64Dict;
+/**
+* @abstract Switch for RTL.
+*
+*/
+ (void)setEnableRTLLayoutDirection:(BOOL)value;
-
+ (BOOL)enableRTLLayoutDirection;
+/**
+* @abstract Switch for dark mode support.
+*
+*/
++ (void)setDarkThemeSupportEnable:(BOOL)value;
++ (BOOL)isDarkThemeSupportEnabled;
+
+ (long) getUnixFixTimeMillis;
+ (NSArray<NSString *> *_Nullable)extractPropertyNamesOfJSValueObject:(JSValue *_Nullable)jsvalue;
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
index 6d7136b..4247725 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
@@ -43,6 +43,7 @@
#define KEY_USERNAME_PASSWORD @"com.taobao.Weex.weex123456"
static BOOL enableRTLLayoutDirection = YES;
+static BOOL isDarkThemeSupportEnabled = YES;
void WXPerformBlockOnMainThread(void (^ _Nonnull block)(void))
{
@@ -181,6 +182,11 @@
+ (NSDictionary *)getEnvironment
{
+ NSString* currentTheme = @"light";
+ if ([WXUtility isDarkThemeSupportEnabled]) {
+ currentTheme = [self isSystemInDarkTheme] ? @"dark" : @"light";
+ }
+
NSString *platform = @"iOS";
NSString *sysVersion = [[UIDevice currentDevice] systemVersion] ?: @"";
NSString *weexVersion = WX_SDK_VERSION;
@@ -204,7 +210,7 @@
@"deviceHeight":@(deviceHeight * scale),
@"scale":@(scale),
@"layoutDirection": [self getEnvLayoutDirection] == WXLayoutDirectionRTL ? @"rtl" : @"ltr",
- @"theme": [self isSystemInDarkTheme] ? @"dark" : @"light"
+ @"theme": currentTheme
}];
if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 11) {
@@ -810,6 +816,18 @@
return enableRTLLayoutDirection;
}
+#pragma mark - Dark theme
+
++ (void)setDarkThemeSupportEnable:(BOOL)value
+{
+ isDarkThemeSupportEnabled = value;
+}
+
++ (BOOL)isDarkThemeSupportEnabled
+{
+ return isDarkThemeSupportEnabled;
+}
+
#pragma mark - get deviceID
+ (NSString *)getDeviceID {
NSMutableDictionary *usernamepasswordKVPairs = (NSMutableDictionary *)[self load:KEY_USERNAME_PASSWORD];