Dark Mode and Dark Theme Settings
Dark color schemes have recently become popular in user interfaces because they
can
reduce eye strain and improve screen readability. iOS and Android now support
dark mode and dark theme, respectively, in their latest versions. To
keep in sync with these developments, Mobile SDK 8.0 adds dark options for its native UI
elements.
Dark schemes affect the following Mobile SDK dialog boxes:
- Choose Connection (server picker)
- Switch User
- Passcode and Biometric Input
Dark settings are managed as follows.
iOS
In Mobile SDK 8.2 and earlier, dark mode always follows the iOS setting on the mobile device. If your app isn’t yet compatible with dark mode, you can disable the feature statically. To do so, open your app’s Info.plist file and set the UIUserInterfaceStyle key to “Light”. Apple strongly recommends that you use this setting only if you need more time to update your app’s resources to dark mode. See “Choosing a Specific Interface Style for Your iOS App” at developer.apple.com.
Mobile SDK 8.3 introduces a userInterfaceStyle
property on SFSDKWindowManager that lets you change the
user interface mode at runtime. This setting applies to all windows that Mobile SDK manages
as follows:
- You can choose dark, light, or unspecified mode. By default, Mobile SDK uses unspecified.
- If an app specifies the plist UIUserInterfaceStyle entry and also sets the userInterfaceStyle property, the property takes precedence.
- This property requires base SDK iOS 13 or later.
Example
These examples use iOS dark theme
APIs.
1// Swift
2SFSDKWindowManager.shared().userInterfaceStyle = .dark
3
4// Objective-C
5[SFSDKWindowManager sharedManager].userInterfaceStyle = UIUserInterfaceStyleDark;Android
Dark theme in Mobile SDK apps is
determined as follows:
- API 29 and higher: Defaults to the OS setting on the mobile device
- API 28 and earlier: Defaults to off
- API 23–29: Apps can force dark theme on or off
In the SalesforceSDKManager class, Mobile SDK provides
APIs for querying and toggling dark theme. If the dark option doesn’t agree with your app’s
existing color scheme, you can revert Mobile SDK resources to the light setting. The Theme enum defines the possible states:
1public enum Theme {
2 LIGHT,
3 DARK,
4 SYSTEM_DEFAULT
5}Example
These examples use Android dark theme APIs.
To
query the theme setting, use this
method:
1public boolean isDarkTheme()To force dark theme on or off, use the setTheme()
method. This example turns off dark theme:
1SalesforceSDKManager.getInstance().setTheme(SalesforceSDKManager.Theme.LIGHT);