Skip to content

Commit

Permalink
fix: root background color change on dark/light view for ios (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr authored Oct 30, 2020
1 parent 3812437 commit f128407
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 62e6d8fc85ac6b63b6370c161340ec610b2d688a

COCOAPODS: 1.9.3
COCOAPODS: 1.10.0
22 changes: 6 additions & 16 deletions ios/atb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2DCD954D1E0B4F2C00145EB5 /* atbTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* atbTests.m */; };
385EE0D3242C0AFC002E1272 /* enforce-bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385EE0D2242C0AFC002E1272 /* enforce-bridge.swift */; };
38CD3270254B612600C6B978 /* AtBRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 38CD326F254B612600C6B978 /* AtBRootView.m */; };
760F020F5EF28EA872E85D1E /* libPods-atb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F4A8BBB63B094DA5F9B2BA8 /* libPods-atb.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -64,6 +65,8 @@
2D02E47B1E0B4A5D006451C7 /* atb-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "atb-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2D02E4901E0B4A5D006451C7 /* atb-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "atb-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
385EE0D2242C0AFC002E1272 /* enforce-bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "enforce-bridge.swift"; sourceTree = "<group>"; };
38CD326F254B612600C6B978 /* AtBRootView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = AtBRootView.m; path = atb/AtBRootView.m; sourceTree = "<group>"; };
38CD3275254B616300C6B978 /* AtBRootView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AtBRootView.h; path = atb/AtBRootView.h; sourceTree = "<group>"; };
38E33D0D242C0838003D56ED /* atb-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "atb-Bridging-Header.h"; sourceTree = "<group>"; };
38F348B52542D8120073C300 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
39BBF66B9FD0BAD989E6DB44 /* Pods-atb-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-atb-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-atb-tvOS/Pods-atb-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +165,8 @@
13B07FB71A68108700A75B9A /* main.m */,
38E33D0D242C0838003D56ED /* atb-Bridging-Header.h */,
385EE0D2242C0AFC002E1272 /* enforce-bridge.swift */,
38CD326F254B612600C6B978 /* AtBRootView.m */,
38CD3275254B616300C6B978 /* AtBRootView.h */,
);
name = atb;
sourceTree = "<group>";
Expand Down Expand Up @@ -466,28 +471,12 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-atb/Pods-atb-frameworks.sh",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/MapboxMobileEvents.framework",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/MapboxMobileEvents.framework.dSYM",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/BADC3E19-B154-39DA-BE9A-E7C52B45BD0C.bcsymbolmap",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/F86F5A50-B0A0-3D96-8330-20AFDAC47DCC.bcsymbolmap",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/877E1F78-505A-34B9-A9A0-42F8BFA435B9.bcsymbolmap",
"${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/7C38D00F-328F-3E0C-B30E-E47F366F0F3D.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/BADC3E19-B154-39DA-BE9A-E7C52B45BD0C.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/F86F5A50-B0A0-3D96-8330-20AFDAC47DCC.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/877E1F78-505A-34B9-A9A0-42F8BFA435B9.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/7C38D00F-328F-3E0C-B30E-E47F366F0F3D.bcsymbolmap",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
"${DWARF_DSYM_FOLDER_PATH}/MapboxMobileEvents.framework.dSYM",
"${BUILT_PRODUCTS_DIR}/BADC3E19-B154-39DA-BE9A-E7C52B45BD0C.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/F86F5A50-B0A0-3D96-8330-20AFDAC47DCC.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/877E1F78-505A-34B9-A9A0-42F8BFA435B9.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/7C38D00F-328F-3E0C-B30E-E47F366F0F3D.bcsymbolmap",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -623,6 +612,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
38CD3270254B612600C6B978 /* AtBRootView.m in Sources */,
385EE0D3242C0AFC002E1272 /* enforce-bridge.swift in Sources */,
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
Expand Down
7 changes: 3 additions & 4 deletions ios/atb/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "AppDelegate.h"
#import "AtBRootView.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>


Expand Down Expand Up @@ -60,16 +60,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
AtBRootView *rootView = [[AtBRootView alloc] initWithBridge:bridge
moduleName:@"atb"
initialProperties:nil];

rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[rootView setBackgroundByTrait];
[self.window makeKeyAndVisible];

[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
Expand Down
4 changes: 4 additions & 0 deletions ios/atb/AtBRootView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <React/RCTRootView.h>
@interface AtBRootView : RCTRootView
-(void)setBackgroundByTrait;
@end
31 changes: 31 additions & 0 deletions ios/atb/AtBRootView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#import "AtBRootView.h"
#import <React/RCTRootView.h>

@implementation AtBRootView

- (void) traitCollectionDidChange: (UITraitCollection *) previousTraitCollection
{
[super traitCollectionDidChange: previousTraitCollection];

if (@available(iOS 13.0, *)) {
if (self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
[self setBackgroundByTrait];
}
}
}

- (void)setBackgroundByTrait
{
if (@available(iOS 13.0, *)) {
if ([UITraitCollection currentTraitCollection].userInterfaceStyle == UIUserInterfaceStyleDark)
{
self.window.rootViewController.view.backgroundColor = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:1];
} else {
self.window.rootViewController.view.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
}
} else {
self.window.rootViewController.view.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
}
}

@end

0 comments on commit f128407

Please sign in to comment.