Commit 6d088b7 1 parent d87d0fc commit 6d088b7 Copy full SHA for 6d088b7
File tree 7 files changed +25
-26
lines changed
7 files changed +25
-26
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ struct TextContentView: View {
14
14
@Environment ( \. layoutDirection)
15
15
private var layoutDirection : LayoutDirection
16
16
17
+ @Environment ( \. characterDirection)
18
+ private var characterDirection : LayoutDirection
19
+
17
20
@EnvironmentObject
18
21
private var settings : ReaderSettings
19
22
@@ -46,20 +49,24 @@ struct TextContentView: View {
46
49
47
50
extension TextContentView {
48
51
private var alignment : Alignment {
49
- switch settings . languageDirection {
52
+ switch characterDirection {
50
53
case . leftToRight:
51
54
return layoutDirection == . leftToRight ? . leading : . trailing
52
55
case . rightToLeft:
53
56
return layoutDirection == . rightToLeft ? . leading : . trailing
57
+ @unknown default :
58
+ return . leading
54
59
}
55
60
}
56
61
57
62
private var textAlignment : TextAlignment {
58
- switch settings . languageDirection {
63
+ switch characterDirection {
59
64
case . leftToRight:
60
65
return layoutDirection == . leftToRight ? . leading : . trailing
61
66
case . rightToLeft:
62
67
return layoutDirection == . rightToLeft ? . leading : . trailing
68
+ @unknown default :
69
+ return . leading
63
70
}
64
71
}
65
72
}
Original file line number Diff line number Diff line change @@ -14,10 +14,14 @@ private struct AuthorizationClientKey: EnvironmentKey {
14
14
static var defaultValue : AuthorizationClient = Services . shared. authClient
15
15
}
16
16
17
- struct SourceKey : EnvironmentKey {
17
+ private struct SourceKey : EnvironmentKey {
18
18
static var defaultValue = Services . shared. source
19
19
}
20
20
21
+ private struct CharacterDirectionKey : EnvironmentKey {
22
+ static var defaultValue : LayoutDirection = . leftToRight
23
+ }
24
+
21
25
extension EnvironmentValues {
22
26
var accessTokenStore : AccessTokenStore {
23
27
get { self [ AccessTokenStoreKey . self] }
@@ -33,4 +37,9 @@ extension EnvironmentValues {
33
37
get { self [ SourceKey . self] }
34
38
set { self [ SourceKey . self] = newValue }
35
39
}
40
+
41
+ var characterDirection : LayoutDirection {
42
+ get { self [ CharacterDirectionKey . self] }
43
+ set { self [ CharacterDirectionKey . self] = newValue }
44
+ }
36
45
}
Original file line number Diff line number Diff line change 5
5
import Foundation
6
6
import Textile
7
7
import Sync
8
+ import SwiftUI
8
9
9
10
public extension Item {
10
- var languageDirection : LanguageDirection {
11
+ var characterDirection : LayoutDirection {
11
12
let language = language ?? " en "
12
13
let direction = Locale . characterDirection ( forLanguage: language)
13
14
return direction == . rightToLeft ? . rightToLeft : . leftToRight
Original file line number Diff line number Diff line change @@ -22,12 +22,14 @@ struct ItemDestinationView: View {
22
22
private var isPresentingOverflow = false
23
23
24
24
@StateObject
25
- private var settings : ReaderSettings
25
+ private var settings = ReaderSettings ( )
26
26
27
27
@ViewBuilder
28
28
private var destinationView : some View {
29
29
if let article = article {
30
- ArticleView ( article: article) . navigationBarHidden ( true )
30
+ ArticleView ( article: article)
31
+ . navigationBarHidden ( true )
32
+ . environment ( \. characterDirection, item. characterDirection)
31
33
} else {
32
34
// TODO: Implement a view for when an article for the item doesn't exist.
33
35
EmptyView ( )
@@ -36,10 +38,6 @@ struct ItemDestinationView: View {
36
38
37
39
init ( item: Item ) {
38
40
self . item = item
39
-
40
- let settings = ReaderSettings ( )
41
- settings. languageDirection = item. languageDirection
42
- _settings = StateObject ( wrappedValue: settings)
43
41
}
44
42
45
43
var body : some View {
Original file line number Diff line number Diff line change @@ -19,10 +19,6 @@ class ItemPresenter: ItemRow {
19
19
public var title : String {
20
20
item. title ?? item. thumbnailURL? . absoluteString ?? " Missing Title "
21
21
}
22
-
23
- public var languageDirection : LanguageDirection {
24
- item. languageDirection
25
- }
26
22
27
23
public var domain : String {
28
24
item. domainMetadata? . name ?? item. domain ?? " "
Original file line number Diff line number Diff line change @@ -12,8 +12,6 @@ class ReaderSettings: ObservableObject {
12
12
13
13
@AppStorage ( " readerFontFamily " )
14
14
var fontFamily : FontDescriptor . Family = . graphik
15
-
16
- var languageDirection : LanguageDirection = . leftToRight
17
15
}
18
16
19
17
extension FontDescriptor . Family : RawRepresentable {
Original file line number Diff line number Diff line change @@ -16,23 +16,14 @@ private extension Style {
16
16
static let detail : Style = . header. sansSerif. p4. with ( color: . ui. grey4)
17
17
}
18
18
19
- public enum LanguageDirection {
20
- case leftToRight
21
- case rightToLeft
22
- }
23
-
24
19
public protocol ItemRow : ObservableObject {
25
20
var title : String { get }
26
- var languageDirection : LanguageDirection { get }
27
21
var domain : String { get }
28
22
var timeToRead : String ? { get }
29
23
var thumbnailURL : URL ? { get }
30
24
}
31
25
32
26
public struct ItemRowView < Model: ItemRow > : View {
33
- @Environment ( \. layoutDirection)
34
- private var layoutDirection
35
-
36
27
private var model : Model
37
28
38
29
public init ( model: Model ) {
@@ -89,7 +80,6 @@ struct ItemRow_Previews: PreviewProvider {
89
80
nascetur ridiculus mus. Donec sed odio dui.
90
81
"""
91
82
92
- var languageDirection : LanguageDirection = . leftToRight
93
83
var domain : String = " Etiam Sem Magna Parturient Bibendum "
94
84
var timeToRead : String ? = " 5 min "
95
85
var thumbnailURL : URL ? = URL ( string: " http://placekitten.com/200/300 " ) !
You can’t perform that action at this time.
0 commit comments