You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PhoenixLiveViewNative Swift package lets you use Phoenix LiveView to build native iOS apps with SwiftUI.
3
+
The LiveViewNative Swift package lets you use Phoenix LiveView to build native iOS apps with SwiftUI.
4
4
5
5
## Resources
6
6
7
-
- Browse the [documentation](https://liveviewnative.github.io/liveview-client-swiftui/documentation/phoenixliveviewnative/) to read about the API.
7
+
- Browse the [documentation](https://liveviewnative.github.io/liveview-client-swiftui/documentation/liveviewnative/) to read about the API.
8
8
- Follow the [tutorial](https://liveviewnative.github.io/liveview-client-swiftui/tutorials/yourfirstapp) to get a step-by-step walkthrough of building an app with LiveView Native.
9
9
- Check out the [ElixirConf '22 chat app](https://github.com/liveviewnative/elixirconf_chat) for an example of a complete app.
Copy file name to clipboardExpand all lines: Sources/LiveViewNative/CustomRegistry.swift
+32-34Lines changed: 32 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,16 @@
1
1
//
2
2
// CustomRegistry.swift
3
-
// PhoenixLiveViewNative
3
+
// LiveViewNative
4
4
//
5
5
// Created by Shadowfacts on 2/16/22.
6
6
//
7
7
8
8
import SwiftUI
9
-
import SwiftSoup
10
-
11
-
// typealiases so people implementing CustomRegistry don't have to also import SwiftSoup
12
-
publictypealiasElement=SwiftSoup.Element
13
-
publictypealiasAttribute=SwiftSoup.Attribute
9
+
import LiveViewNativeCore
14
10
15
11
/// A custom registry allows clients to include custom view types in the LiveView DOM.
16
12
///
17
-
/// To add a custom element or attribute, define an enum for the type alias for the tag/attribute name and implement the appropriate method. To customize the loading view, implement the ``loadingView(for:state:)-vg2v`` method.
13
+
/// To add a custom element or attribute, define an enum for the type alias for the tag/attribute name and implement the appropriate method. To customize the loading view, implement the ``loadingView(for:state:)-2uoy9`` method.
18
14
///
19
15
/// To use your custom registry implementation, provide it as the generic parameter for the ``LiveViewCoordinator`` you construct:
20
16
///
@@ -27,13 +23,15 @@ public typealias Attribute = SwiftSoup.Attribute
/// A type represnting the attribute names that this registry can handle.
58
+
/// A type represnting the custom modifier types that this registry can handle.
61
59
///
62
-
/// The attribute name type must be `RawRepresentable` and its raw values must be strings. All raw value strings must be lowercased, otherwise the framework will not be able to construct your attribute types from strings in the DOM.
60
+
/// This type must be `RawRepresentable` and its raw values must be strings.
63
61
///
64
62
/// Generally, this is an enum which declares variants for the support attributes:
65
63
/// ```swift
66
64
/// struct MyRegistry: CustomRegistry {
67
65
/// enum AttributeName: String {
68
66
/// case foo
69
-
/// case barBaz = "bar-baz"
67
+
/// case barBaz
70
68
/// }
71
69
/// }
72
70
/// ```
73
71
///
74
-
/// If your registry does not support any custom attributes, you can set this type alias to the ``EmptyRegistry/None`` type:
72
+
/// If your registry does not support any custom modifiers, you can set this type alias to the ``EmptyRegistry/None`` type:
/// The type of view this registry returns from the `lookup` method.
82
80
///
83
-
/// Generally, implementors will use an opaque return type on their ``lookup(_:element:context:)-2rzrl`` implementations and this will be inferred automatically.
81
+
/// Generally, implementors will use an opaque return type on their ``lookup(_:element:context:)-895au`` implementations and this will be inferred automatically.
84
82
associatedtypeCustomView:View
85
83
/// The type of view this registry produces for loading views.
86
84
///
87
-
/// Generally, implementors will use an opaque return type on their ``loadingView(for:state:)-vg2v`` implementations and this will be inferred automatically.
85
+
/// Generally, implementors will use an opaque return type on their ``loadingView(for:state:)-2uoy9`` implementations and this will be inferred automatically.
88
86
associatedtypeLoadingView:View
89
87
90
88
/// This method is called by LiveView Native when it needs to construct a custom view.
@@ -95,18 +93,18 @@ public protocol CustomRegistry {
95
93
/// - Parameter element: The element that a view should be created for.
96
94
/// - Parameter context: The live context in which the view is being created.
/// This method is called by LiveView Native when it encounters a custom attribute your registry has declared support for.
98
+
/// This method is called by LiveView Native when it encounters a view modifier your registry has declared support for.
101
99
///
102
-
/// If your custom registry does not support any attributes, you can set the `AttributeName` type alias to ``EmptyRegistry/None`` and omit this method.
100
+
/// If your custom registry does not support any custom modifiers, you can set the `ModifierType` type alias to ``EmptyRegistry/None`` and omit this method.
103
101
///
104
-
/// - Parameter name: The name of the attribute.
105
-
/// - Parameter value: The value of the attribute. If no value is provided in the DOM, an empty string will be used as the value.
106
-
/// - Parameter element: The element on which the attribute is present.
102
+
/// - Parameter type: The type of the modifier.
103
+
/// - Parameter decoder: The decoder representing the JSON object of the modifier. Implement `Decodable` on your modifier type and call `MyModifier(from: decoder)` to use it.
107
104
/// - Parameter context: The live context in which the view is being built.
108
105
/// - Returns: A struct that implements the `SwiftUI.ViewModifier` protocol.
staticfunc decodeModifier(_ type:ModifierType, from decoder:Decoder, context:LiveContext<Self>)throws->anyViewModifier
110
108
111
109
/// This method is called when it needs a view to display while connecting to the live view.
112
110
///
@@ -129,7 +127,7 @@ extension CustomRegistry where LoadingView == Never {
129
127
publicstructEmptyRegistry{
130
128
}
131
129
extensionEmptyRegistry:CustomRegistry{
132
-
/// A type that can be used as ``CustomRegistry/TagName`` or ``CustomRegistry/AttributeName`` for registries which don't support any custom tags or attributes.
130
+
/// A type that can be used as ``CustomRegistry/TagName`` or ``CustomRegistry/ModifierType`` for registries which don't support any custom tags or attributes.
/// A default implementation that does not provide any custom elements. If you omit the ``CustomRegistry/TagName`` type alias, this implementation will be used.
/// A default implementation that does not provide any custom attributes. If you omit the ``CustomRegistry/AttributeName`` type alias, this implementation will be used.
/// A default implementation that does not provide any custom modifiers. If you omit the ``CustomRegistry/ModifierType`` type alias, this implementation will be used.
151
+
publicstaticfuncdecodeModifier(_ type:ModifierType, from decoder:Decoder, context:LiveContext<Self>)->anyViewModifier{
0 commit comments