Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardiman committed Jul 18, 2019
1 parent 36b8bb6 commit 85371b0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The "key" will be used as a static property name in a `class` so should have a f
- `Double`: A double value
- `Bool`: A boolean value
- `Colour`: A colour in hex format, will be output as a `UIColor`.
- `DynamicColour`: A pair of colours, in hex format, that will be output as an iOS 13-compatible dynamic colour.
- `DynamicColourReference`: A pair of colours, as properties on the current configuration or somewhere else, that will be output as an iOS 13-compatible dynamic colour.
- `Image`: The name of an image. Will be converted to `UIImage(named: "the value")!`.
- `Regex`: A regular expression pattern. Will be converted to `try! NSRegularExpression(patthen: "the value", options: [])`
- `EncryptionKey`: A key to use to encrypt sensitive info.
Expand Down Expand Up @@ -224,6 +226,67 @@ If you find yourself repeating override patterns, for example `(PROD|STAGING)` y
}
```

### DynamicColour and DynamicColourReference
To support iOS 13's dark mode, it is possible to output colours as dynamic. For example:

```
"background": {
"type": "DynamicColour",
"defaultValue": {
"light": "#FF",
"dark": "#00"
}
}
```

will output:

```
@nonobjc static var background: UIColor {
if #available(iOS 13, *) {
return UIColor(dynamicProvider: {
if $0.userInterfaceStyle == .dark {
return UIColor(white: 0.0 / 255.0, alpha: 1.0)
} else {
return UIColor(white: 255.0 / 255.0, alpha: 1.0)
}
})
} else {
return UIColor(white: 255.0 / 255.0, alpha: 1.0)
}
}
```

Similarly, it is possible to use references to another colour, so:

```
"background": {
"type": "DynamicColourReference",
"defaultValue": {
"light": "UIColor.white",
"dark": "UIColor.black"
}
}
```

will output:

```
@nonobjc static var background: UIColor {
if #available(iOS 13, *) {
return UIColor(dynamicProvider: {
if $0.userInterfaceStyle == .dark {
return UIColor.black
} else {
return UIColor.white
}
})
} else {
return UIColor.white
}
}
```

## Writing your own schemas
Just add a new class or struct to the project and implement `Template`. Add your new parser to the `templates` array in main.swift. Your template should inspect a `template` dictionary in any config and decide whether it can parse it. Either using a `name` item, or through other means. Ensure `ConfigurationFile` is the last item in that array. As the default schema parser it claims to be able to parse all files.

Expand Down

0 comments on commit 85371b0

Please sign in to comment.