Skip to content

Commit ac0d39c

Browse files
committed
feat: initial commit
0 parents  commit ac0d39c

File tree

19 files changed

+905
-0
lines changed

19 files changed

+905
-0
lines changed

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.DS_Store
2+
3+
**/.DS_Store
4+
5+
## Various settings
6+
*.pbxuser
7+
!default.pbxuser
8+
*.mode1v3
9+
!default.mode1v3
10+
*.mode2v3
11+
!default.mode2v3
12+
*.perspectivev3
13+
!default.perspectivev3
14+
iphone/xcuserdata/
15+
16+
## Other
17+
*.moved-aside
18+
*.xccheckout
19+
*.xcscmblueprint
20+
ios/metadata.json
21+
ios/build/
22+
ios/ti.darkmode.xcodeproj/project.xcworkspace/xcuserdata/
23+
ios/ti.darkmode-iphone-*.zip
24+
android/build
25+
android/dist/ti.aws-android-*.zip
26+
android/.gradle
27+
ios/dist
28+
ios/titanium-darkmode.xcodeproj/xcuserdata/
29+
*.xcuserstate

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# iOS 13+ Dark Mode in Titanium
2+
3+
Full support for iOS 13+ dark mode in Titanium. Even works if colors are changed at runtime.
4+
5+
## The Magic
6+
7+
This project includes a CLI hook that generates semantic colors for the iOS Asset Catalog based on a JSON
8+
file of colors that can even be used cross-platform and backwards compatible. It hooks into the SDK process
9+
between generating the asset catalog and compiling the app, so you can even change colors between builds
10+
without the need of clean-building the app again.
11+
12+
## Requirements
13+
14+
The following project- and OS-requirements are necessary:
15+
16+
- [x] Xcode 11+
17+
- [x] Asset Catalog enabled
18+
- [x] iOS 13+ (will fallback to `#000000` if called from older devices)
19+
- [x] Titanium SDK 8.0.0+
20+
- [x] A CLI plugin to hook into the asset catalog to generate the semantic colors
21+
- [x] A JSON file to curate the color styles
22+
23+
## Installation
24+
25+
- [x] Copy the contents of the `plugin/` directory (`colors`) to `<project>/plugins`
26+
- [x] Link the `colors` plugin in your tiapp.xml:
27+
```xml
28+
<ti:app>
29+
<!-- ... -->
30+
<plugins>
31+
<!-- ... -->
32+
<plugin version="1.0">colors</plugin>
33+
</plugins>
34+
</ti:app>
35+
```
36+
- [x] Link the native `ti.darkmode` module to your project like any other native module
37+
- [x] Alloy: Copy your color JSON file to `<project>/app/assets/json/colors.json`
38+
- [x] Classic: Copy your color JSON file to `<project>/Resources/json/colors.json`
39+
- [x] Map the colors on runtime for older devices or Android (this is just an example of how this could look like):
40+
```js
41+
function initializeColors() {
42+
const colors = Alloy.Globals.colors = JSON.parse(Ti.Filesystem.getFile('json/colors.json').read());
43+
const darkmode = OS_ANDROID ? undefined : require('ti.darkmode');
44+
45+
for (const color of Object.keys(colors)) {
46+
Alloy.CFG.styles[color] = Utils.isiOSVersionOrGreater(13) ? darkmode.fetch(color) : colors[color].light;
47+
}
48+
49+
// Use your colors like the following
50+
myLabel.backgroundColor = Alloy.CFG.styles.backgroundColor
51+
}
52+
```
53+
54+
## Notes
55+
56+
The native module returns a native `TiColor` object that holds a reference to the native `UIColor` object. Unfortunately, not all
57+
Titanium API's can consume this object so far, so you might require an SDK update to support this to 100 %. A pull request
58+
is pending and should be merged before iOS 13 is released.
59+
60+
## License
61+
62+
MIT
63+
64+
## Author
65+
66+
Hans Knöchel

example/colors.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"backgroundColor": {
3+
"light": "#f6f6f9",
4+
"dark": "#000000"
5+
},
6+
"textColor": {
7+
"light": "#000000",
8+
"dark": "#ffffff"
9+
},
10+
"tintColor": {
11+
"light": "#ff0000",
12+
"dark": "#00ff00"
13+
}
14+
}

ios/Classes/TiDarkmodeModule.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* titanium-darkmode
3+
*
4+
* Created by Your Name
5+
* Copyright (c) 2019 Your Company. All rights reserved.
6+
*/
7+
8+
#import "TiModule.h"
9+
10+
@interface TiDarkmodeModule : TiModule {
11+
12+
}
13+
14+
@end

ios/Classes/TiDarkmodeModule.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* titanium-darkmode
3+
*
4+
* Created by Your Name
5+
* Copyright (c) 2019 Your Company. All rights reserved.
6+
*/
7+
8+
#import "TiDarkmodeModule.h"
9+
#import "TiBase.h"
10+
#import "TiHost.h"
11+
#import "TiUtils.h"
12+
13+
@implementation TiDarkmodeModule
14+
15+
#pragma mark Internal
16+
17+
- (id)moduleGUID
18+
{
19+
return @"84d35a8b-b374-4b91-9fb9-3fe0e0b6a7e1";
20+
}
21+
22+
- (NSString *)moduleId
23+
{
24+
return @"ti.darkmode";
25+
}
26+
27+
#pragma Public APIs
28+
29+
- (TiColor *)fetch:(id)color
30+
{
31+
ENSURE_SINGLE_ARG(color, NSString);
32+
33+
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
34+
return [[TiColor alloc] initWithColor:[UIColor colorNamed:color] name:nil];
35+
} else {
36+
return [[TiColor alloc] initWithColor:UIColor.blackColor name:@"black"];
37+
}
38+
}
39+
40+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* This is a generated file. Do not edit or your changes will be lost
3+
*/
4+
5+
@interface TiDarkmodeModuleAssets : NSObject {
6+
7+
}
8+
9+
- (NSData *)moduleAsset;
10+
- (NSData *)resolveModuleAsset:(NSString*)path;
11+
12+
@end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* This is a generated file. Do not edit or your changes will be lost
3+
*/
4+
#import "TiDarkmodeModuleAssets.h"
5+
6+
extern NSData* filterDataInRange(NSData* thedata, NSRange range);
7+
8+
@implementation TiDarkmodeModuleAssets
9+
10+
- (NSData *)moduleAsset
11+
{
12+
13+
14+
return nil;
15+
}
16+
17+
- (NSData *)resolveModuleAsset:(NSString *)path
18+
{
19+
20+
21+
return nil;
22+
}
23+
24+
@end

ios/Resources/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Files in this folder are copied directory into the compiled product directory
2+
when the iOS app is compiled:
3+
4+
<project-dir>/build/iphone/build/Products/<Debug-iphonesimulator|Release-iphoneos>/<app name>.app/
5+
6+
Place your module's iOS bundles and localization files in this folder.
7+
8+
Files in this directory are copied directly on top of whatever files are already
9+
in the build directory, so please be careful that your files don't clobber
10+
essential project files or files from other modules.

ios/TiDarkmode_Prefix.pch

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#ifdef __OBJC__
3+
#import <Foundation/Foundation.h>
4+
#import <UIKit/UIKit.h>
5+
#endif

ios/manifest

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# this is your module manifest and used by Titanium
3+
# during compilation, packaging, distribution, etc.
4+
#
5+
version: 1.0.0
6+
apiversion: 2
7+
architectures: armv7 arm64 i386 x86_64
8+
description: titanium-darkmode
9+
author: Your Name
10+
license: Specify your license
11+
copyright: Copyright (c) 2019 by Your Company
12+
13+
# these should not be edited
14+
name: titanium-darkmode
15+
moduleid: ti.darkmode
16+
guid: 84d35a8b-b374-4b91-9fb9-3fe0e0b6a7e1
17+
platform: iphone
18+
minsdk: 8.0.0

0 commit comments

Comments
 (0)