Open julien-deramond opened 2 months ago
For information, a first draft is available in the implementation of #33 due to the need to test the architect with available tokens. Of course any improvements, fixes and implementations after the merge of #33 must be linked to this issue to keep consistency.
In addition, "shared" raw tokens defined in OUDSTheme
module (common to all themes) are not customisable as is in OUDS iOS and should not supposed to be because they define raw types and true values for everything, like a kind of source of truth for everyone. However any theme can define its own raw tokens and assign them to semantic tokens. Of course raw tokens values can be defined thanks to generated Swift code, if we have any efficient and relevant tools suite.
What should be done for this issue:
@julien-deramond is "Box shadow (Composite)" a raw token for elevation too? Is so, what does box-shadow: 0 1px 2px 0 rgba({core.color.transparent.black.100}); mean?
About the colors, we agreed with Android side to put the "inverse" colors in a dedicaed "Inverse theme".
@julien-deramond FYI some raw tokens as values of semantic tokens are missing: zindex-1035, zindex-1038, zindex-1045. I may remember they were listed in design team white board, so I implement them. Maybe the issue should be updated.
@julien-deramond FYI some raw tokens as values of semantic tokens are missing: zindex-1035, zindex-1038, zindex-1045. I may remember they were listed in design team white board, so I implement them. Maybe the issue should be updated.
Good catch! I've updated the description with the missing values in all repositories. You can resolve your comment and mine.
About the colors, we agreed with Android side to put the "inverse" colors in a dedicaed "Inverse theme".
Be careful, the color definition/specification is not defined/finalized yet. We might have only the light and dark modes, and the "inverse" being the contextual dark mode.
@julien-deramond is "Box shadow (Composite)" a raw token for elevation too? Is so, what does box-shadow: 0 1px 2px 0 rgba({core.color.transparent.black.100}); mean?
It's a token that is a group of raw values (and sometimes associated with a cascade of raw tokens).
Its value would be 0 1px 2px 0 rgba({core.color.transparent.black.100});
(which is not correct as you wouldn't have rgba
which is already in core.color.transparent.black.100
btw).
In the web world, it would mean something like that, for instance, https://codepen.io/julien-deramond/pen/jOjwywZ:
// Raw
$color-black: #000;
$opacity-100: 0.04;
$color-transparent-black-100: rgba($color-black , $opacity-100);
$elevation-box-shadow-bottom-1-100: 0 1px 2px 0 $color-transparent-black-100;
// Semantic
$elevation-box-shadow-something: $elevation-box-shadow-bottom-1-100;
.example-element {
box-shadow: $elevation-box-shadow-something;
}
On your side, it might be handled differently.
Ok, but I would like to know what are the 0 1px 2px 0 values in your raw token. I needed to understand what they are and how they should be used so as to define this token in iOS side.
Ok, but I would like to know what are the 0 1px 2px 0 values in your raw token. I needed to understand what they are and how they should be used so as to define this token in iOS side.
It follows the CSS syntax: https://developer.mozilla.org/fr/docs/Web/CSS/box-shadow#syntaxe (in French)
What should be the token value of the raw token "elevation-box-shadow-bottom-0"? We cannot guess what must be X, Y, blur, spread and colors.
In order to test our CI/CD pipeline velocity, avoid to have stale branches, have a fresh code abse for documentation and test our production build (for a fake 0.0.0 version), a first version of the tokens has been merged as is, but the issue is not closed because there are some topics to deal about these elevation tokens.
What should be its core values? We need to know what must be its X, Y, blur, spread and color values. We assume today the "inverse" mode is considered as a dedicated theme with the same value for the light and dark colors.
cc @B3nz01d @mccart77 @ludovic35
FYI first version delivered with commit bd373b48aee005d52e0aca69343573cca0e386eb and released before version 0.1.0
FYI after a meeting today this token will be updated in the design team source of truth with values to apply for the token elevation-box-shadow-bottom-0.
Some notes after our last meeting of this afternoon bellow.
First, "composite tokens" are defined in the design team source of truth but won't be exported and processed as is through the style dictionary tool.
So, until the design tool is ready to export such composite tokens, we should deal with values exported in another fashion.
Design tool for elevations is based on notions of blur and spread, however we managed radius values in SwiftUI and not blur and spread
In addition we have today implemented composite semantic tokens, pointing to composite raw tokens, using raw values, e.g.:
// Composite semantic token "elevationBoxShadowRaisedLight" pointing to composite raw token "elevationBoxShadowBottom_1_500"
public override var elevationBoxShadowRaisedLight: ElevationBoxShadowSemanticToken { ElevationRawTokens.elevationBoxShadowBottom_1_500 }
// Composite raw token "elevationBoxShadowBottom_1_500" using raw values for x, Y, blur, spread and color, even if it does not make sense with SwftUI API
public static let elevationBoxShadowBottom_1_500 = ElevationBoxShadowRawToken(x: 0, y: 1, blur: 2, spread: 0, color: ColorRawTokens.colorTransparentBlack500)
// Definition of the type of composite raw token for elevation bow shadow
public class ElevationBoxShadowRawToken: NSObject { // For @objc compatibility
public let x: ElevationRawToken
public let y: ElevationRawToken
public let blur: ElevationRawToken
public let spread: ElevationRawToken
public let color: ColorRawToken
// ...
}
So, the issue is to be able to define the suitable elevation effects with the inputs generated by the JSON parser.
If we get blur and spread values from parser output, we may be able to define the radius for SwiftUI to apply. Then the standard API of SwftUI will be used like:
.shadow(color:, radius:, x:, y:)
The question is: how can we combine blur and spread to get radius?
Maybe the following code sample may help, but it seems to be a bit dirty tinkering
func customShadow(blur: CGFloat, spread: CGFloat) -> some View {
Rectangle()
.fill(Color.clear)
.frame(width: 100 + spread * 2, height: 100 + spread * 2)
.shadow(color: Color.black.opacity(0.5), radius: blur, x: 0, y: 5)
}
/*
About the opacity: of 0.5, it gives the shadow a semi-transparent effect, making it softer and more natural. need to check with design team what this want or need.
About the spread calculation, it is simulated by increasing the size of the overlay rectangle. For example, if we want a spread of 5, the overlay dimensions are increased by 10 (5 on each side).
Warning, the customShadow() method may need to know the dimensions of the parent view frame.
*/
struct ContentView: View {
var body: some View {
Rectangle()
.fill(Color.blue)
.frame(width: 100, height: 100)
.overlay(customShadow(blur: 10, spread: 5)) // <--- Interesting call
}
}
/* Where:
- Blur: Controlled by the radius parameter in the shadow modifier.
- Spread: Simulated by adjusting the size of an overlay and applying a shadow to it.
*/
According to this Stack Overflow thread, it might by possible to extend the CALayer
and using a UIBezierPath
to define some effect, but this algorithm is defined for Sketch, and there are key differences between their implementation and the one in Figma, Sketch having issues with spread notions
However this code sample may help with another definition of shadow radius combinations more tight to Figma.
import SwiftUI
func computeShadowRadius(blur: CGFloat, spread: CGFloat) -> CGFloat {
return spread >= 0 ? blur + spread : blur - abs(spread) // Dirty suggested code be the idea to test is here
}
struct ContentView: View {
var body: some View {
Rectangle()
.fill(Color.blue)
.frame(width: 100, height: 100)
.shadow(color: Color.black.opacity(0.5), radius: computeShadowRadius(blur: 10, spread: 5), x: 0, y: 5)
}
}
cc @ludovic35 @julien-deramond
Still wating for screen shots of design team with a rendering of some simple view and its elevation effect depending to blur and spread values. Did not succeed in finding in the amount of tools where this document is.
Find attached a ZIP archive containing the Swift demo code and its Git patch, and also 2 screenshots (iPhone and iPad) showing the rendering of the elevation effects.
Description
The aim of this issue is to study and implement the elevation tokens taking into account the cohesive multi-platform approach, the customization by libraries inheriting OUDS iOS, but also what we're using for OUDS iOS: Swift UI, etc.
Reminder: there will be in the end 3 layers of tokens:
Tokens: Elevation
Raw primitive values
Z-index
X
Y
Blur
Spread
Box shadow (Composite)
Semantic applications
Z-index
X
Y
Blur
Spread
Color
Box shadow (Composite)
Study
Technical details
TODO