Skip to content

Commit 70e992d

Browse files
pylappludovic35
andauthored
feat: add tokens section (border, elevation, opacity, typography) in demo app (#120) (#137)
Co-authored-by: Ludovic PINEL <[email protected]> Co-authored-by: Pierre-Yves Lapersonne <[email protected]> Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
1 parent 7407979 commit 70e992d

File tree

82 files changed

+1792
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1792
-488
lines changed

.swiftlint.yml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ excluded:
3131
- Showcase/Pods
3232
- Showcase/DerivedData
3333

34+
strict: true
35+
3436
# ==============
3537
# Disabled rules
3638
# ==============

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- [Library] Add color semantic tokens `colorBackgroundStatusNeutral`, some `OnBackgroundEmphasized`, `colorBackgroundAction`, `colorBackgroundAlways`, `colorContent` variants
1212
- [Library] Add typography semantic tokens for font letter spacing
13+
- [DemoApp] Create token section (Border, Typography, Elevation, Opacity) ([#120](https://github.com/Orange-OpenSource/ouds-ios/issues/120))
1314
- [Library] Unit tests for multiple tokens
1415
- [Library] Add color semantic composite tokens embeding light and dark modes values
1516
- [Library] Add spacing semantic tokens "huge" and "jumbo"

NOTICE.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ Any use or displaying shall constitute an infringement under intellectual proper
6666
./Showcase/Showcase/Resources/Assets.xcassets/AppIconQualif.appiconset/[email protected]
6767
./Showcase/Showcase/Resources/Assets.xcassets/AppIconQualif.appiconset/[email protected]
6868

69-
./Showcase/Showcase/Resources/Assets.xcassets/ic_guideline_dna.imageset/ic_guideline_dna.svg
69+
./Showcase/Showcase/Resources/Assets.xcassets/ic_token.imageset/ic_token.svg
7070
./Showcase/Showcase/Resources/Assets.xcassets/ic_component_atom.imageset/ic_component_atom.svg
7171
./Showcase/Showcase/Resources/Assets.xcassets/ic_info.imageset/ic_info.svg
72+
./Showcase/Showcase/Resources/Assets.xcassets/Illustrations/il_empty_screen.imageset/il_empty_screen.svg
73+
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_border.imageset/ic_border.svg
74+
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_filter_effects.imageset/ic_filter_effects.svg
75+
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_layers.imageset/ic_layers.svg
76+
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_typography.imageset/ic_typography.svg
77+
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_union.imageset/ic_union.svg
7278

7379
End of the parts list under Orange SA Copyright

OUDS/Core/Components/Sources/Buttons/OUDSButton.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
1212
//
1313

14-
import Foundation
14+
import OUDS
1515
import OUDSFoundations
1616
import OUDSTokensSemantic
1717
import SwiftUI
@@ -63,10 +63,10 @@ public struct OUDSButton: View {
6363
.foregroundColor(colorScheme == .light
6464
? theme.buttonForegroundColor.light.color
6565
: theme.buttonForegroundColor.dark.color)
66-
.modifier(BorderStyleModifier(theme.buttonBorderStyle,
67-
theme.buttonBorderWidth,
68-
theme.buttonBorderRadius,
69-
theme.buttonBorderColor))
66+
.oudsBorder(style: theme.buttonBorderStyle,
67+
width: theme.buttonBorderWidth,
68+
radius: theme.buttonBorderRadius,
69+
color: theme.buttonBorderColor)
7070
}.frame(width: theme.buttonWidth, height: theme.buttonHeight)
7171
}
7272
}

OUDS/Core/Components/Sources/Extensions/View+Font.swift

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
1212
//
1313

14-
import Foundation
1514
import OUDSTokensSemantic
1615
import SwiftUI
1716

OUDS/Core/Components/Sources/Extensions/View+Shadows.swift

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@
1111
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
1212
//
1313

14-
import Foundation
15-
import OUDSTokensSemantic
14+
import OUDSTokensRaw
1615
import SwiftUI
1716

1817
extension View {
1918

2019
/// Wraps the *SwiftUI* `shadow(color:radius:x:y)` method so as to use as `radius` value
21-
/// the computed `radius` value of the given `ElevationCompositeSemanticToken`.
20+
/// the computed `radius` value of the given `ElevationCompositeRawToken`.
2221
/// - Parameter elevation: The token to give for the shadow / elevation effect
2322
/// - Returns `View`: The current `View` with the shadow / elevation effect
24-
public func shadow(elevation: ElevationCompositeSemanticToken) -> some View {
25-
// TODO: Manage light and dark color scheme
23+
public func shadow(elevation: ElevationCompositeRawToken) -> some View {
2624
return self
27-
.shadow(color: elevation.light.color.color,
28-
radius: elevation.light.radius,
29-
x: CGFloat(elevation.light.x),
30-
y: CGFloat(elevation.light.y))
25+
.shadow(color: elevation.color.color,
26+
radius: elevation.radius,
27+
x: CGFloat(elevation.x),
28+
y: CGFloat(elevation.y))
3129
}
3230
}

OUDS/Core/Components/Sources/Extensions/View+Typography.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
1212
//
1313

14-
import Foundation
1514
import OUDS
1615
import SwiftUI
1716

@@ -191,15 +190,15 @@ extension View {
191190
/// The current `OUDSTheme` must be given in parameter because `@Environment` property cannot be accessed through an extension or inside a method.
192191
/// - Parameter theme: The current `OUDSTheme` to use to load the current font family and the suitable typography semantic token.
193192
/// - Returns some View: The current `View` but with new typography applied
194-
public func typeLabelCodeMedium(_ theme: OUDSTheme) -> some View {
193+
public func typeCodeMedium(_ theme: OUDSTheme) -> some View {
195194
self.modifier(TypographyModifier(customFontFamily: theme.customFontFamily, typography: theme.typeCodeMedium))
196195
}
197196

198197
/// Modifies the current `View` to apply a *code small* typography.
199198
/// The current `OUDSTheme` must be given in parameter because `@Environment` property cannot be accessed through an extension or inside a method.
200199
/// - Parameter theme: The current `OUDSTheme` to use to load the current font family and the suitable typography semantic token.
201200
/// - Returns some View: The current `View` but with new typography applied
202-
public func typeLabelCodeSmall(_ theme: OUDSTheme) -> some View {
201+
public func typeCodeSmall(_ theme: OUDSTheme) -> some View {
203202
self.modifier(TypographyModifier(customFontFamily: theme.customFontFamily, typography: theme.typeCodeSmall))
204203
}
205204
}

OUDS/Core/Components/Sources/Forms/TextInput/OUDSFormsTextInput.swift

-80
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// Software Name: OUDS iOS
3+
// SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
// SPDX-License-Identifier: MIT
5+
//
6+
// This software is distributed under the MIT license,
7+
// the text of which is available at https://opensource.org/license/MIT/
8+
// or see the "LICENSE" file for more details.
9+
//
10+
// Authors: See CONTRIBUTORS.txt
11+
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
12+
//
13+
14+
import SwiftUI
15+
16+
// MARK: - Accessible Navigation Title Modifier
17+
18+
/// `ViewModifier` which defines a navigation title for the calling `View` and also uses `UIAccessibility` to notify for screen changed.
19+
struct AccessibleNavigationTitleModifier: ViewModifier {
20+
21+
/// The title used as a `LocalizedStringKey` to add as navigation title
22+
let title: String
23+
24+
/// Elapsed time to wait before sending an accessibility notification of a screen change with the `title` in argument
25+
let deadline: DispatchTime
26+
27+
func body(content: Content) -> some View {
28+
content
29+
.navigationTitle(LocalizedStringKey(title))
30+
.onAppear {
31+
DispatchQueue.main.asyncAfter(deadline: deadline) {
32+
UIAccessibility.post(notification: .screenChanged, argument: title)
33+
}
34+
}
35+
}
36+
}
37+
38+
// MARK: - Request Accessible Focus Modifier
39+
40+
/// `ViewModifier` to apply on a a `View` so as to request the focus after a given time.
41+
struct RequestAccessibleFocusModifier: ViewModifier {
42+
43+
/// Flag to listen saying wether or not the `View` got the focus
44+
@AccessibilityFocusState var requestFocus: Bool
45+
46+
/// Elapsed time to wait before requesting the focus
47+
let deadline: DispatchTime
48+
49+
func body(content: Content) -> some View {
50+
content.onAppear {
51+
DispatchQueue.main.asyncAfter(deadline: deadline) {
52+
requestFocus = true
53+
}
54+
}
55+
}
56+
}
57+
58+
// MARK: - Accessibility Focusable
59+
60+
public enum AccessibilityFocusable: Hashable {
61+
case none
62+
case some(id: String)
63+
}
64+
65+
// MARK: - Restricted Request Accessible Focus Modifier
66+
67+
/// `ViewModifier` to apply on a `View` to request the focus on that `View` after a given time
68+
struct RestrictedRequestAccessibleFocusModifier: ViewModifier {
69+
70+
/// Flag to listen saying wether or not the `View` got the focus
71+
@AccessibilityFocusState var requestFocus: AccessibilityFocusable?
72+
73+
/// The target to give the focus after the deadLine` delay
74+
let target: AccessibilityFocusable
75+
76+
/// Elapsed time to wait before requesting the focus
77+
let deadline: DispatchTime
78+
79+
func body(content: Content) -> some View {
80+
content.onAppear {
81+
DispatchQueue.main.asyncAfter(deadline: deadline) {
82+
requestFocus = target
83+
}
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Software Name: OUDS iOS
3+
// SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
// SPDX-License-Identifier: MIT
5+
//
6+
// This software is distributed under the MIT license,
7+
// the text of which is available at https://opensource.org/license/MIT/
8+
// or see the "LICENSE" file for more details.
9+
//
10+
// Authors: See CONTRIBUTORS.txt
11+
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
12+
//
13+
14+
import SwiftUI
15+
16+
// MARK: - Accessibility Delay
17+
18+
/// Contains some delays to apply to view modifiers' deadlines for vocalizations or accessibility notifications
19+
private enum AccessibilityDelay: Double {
20+
// Must be lower than accesibleFocusRequestDelay to start before
21+
case accessibleTitleNotificationDelay = 0.0
22+
// Must be greater than accessibleTitleNotificationDelay to start after
23+
case accessibleFocusRequestDelay = 1.0
24+
}
25+
26+
// MARK: - View extension
27+
28+
extension View {
29+
30+
/// Adds a modifier to the current `View` so as to define a navigation title using the current `title`
31+
/// and also send a notification for accessibility layers for a change of screen when appeared.
32+
/// - Parameter title: The navigation title
33+
/// - Returns View: The view with a new modifier
34+
public func oudsNavigationTitle(_ title: String) -> some View {
35+
self.modifier(AccessibleNavigationTitleModifier(title: title,
36+
deadline: .now() + AccessibilityDelay.accessibleTitleNotificationDelay.rawValue))
37+
}
38+
39+
/// Adds a modifier to the current `View` so as to defer a focus request after the view is displayed
40+
/// - Parameter requestFocus: The boolean binding (e.g. the `AccessibilityFocusState`)
41+
/// - Returns View: The view with a new modifier
42+
public func oudsRequestAccessibleFocus(_ requestFocus: AccessibilityFocusState<Bool>) -> some View {
43+
self.modifier(RequestAccessibleFocusModifier(requestFocus: requestFocus,
44+
deadline: .now() + AccessibilityDelay.accessibleFocusRequestDelay.rawValue))
45+
}
46+
47+
/// Adds a modifier to the current `View` so as to defer a focus request after the view is displayed for the given element
48+
/// - Parameters:
49+
/// - requestFocus: The boolean binding (e.g. the `AccessibilityFocusState`)
50+
/// - target: The item which will get the focus
51+
/// - Returns View: The view with a new modifier
52+
public func oudsRequestAccessibleFocus(_ requestFocus: AccessibilityFocusState<AccessibilityFocusable?>, for target: AccessibilityFocusable) -> some View {
53+
self.modifier(RestrictedRequestAccessibleFocusModifier(requestFocus: requestFocus,
54+
target: target,
55+
deadline: .now() + AccessibilityDelay.accessibleFocusRequestDelay.rawValue))
56+
}
57+
}

0 commit comments

Comments
 (0)