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
Text("Hello from SwiftUI").Compose(context: context.content())
117
+
androidx.compose.material3.Text("Hello from Compose")
118
+
}
119
+
}
120
+
}
121
+
#endif
122
+
```
105
123
106
124
Skip Lite:
107
125
@@ -118,8 +136,6 @@ ComposeView { context in
118
136
119
137
With `ComposeView` and the `Compose(context:)` function, you can move fluidly between SwiftUI and Compose code. These techniques work not only with standard SwiftUI and Compose components, but with your own custom SwiftUI views and Compose functions as well.
120
138
121
-
`ComposeView` and the `Compose()` function are only available in Android, so you must guard all uses with the `#if SKIP` compiler directives.
122
-
123
139
### Additional Considerations
124
140
125
141
There are additional considerations when integrating SwiftUI into a Compose application that is **not** managed by Skip. SwiftUI relies on its own mechanisms to save and restore `Activity` UI state, such as `@AppStorage` and navigation path bindings. It is not compatible with Android's `Activity` UI state restoration. Use a pattern like the following to exclude SwiftUI from `Activity` state restoration when integrating SwiftUI views:
@@ -136,7 +152,51 @@ This pattern allows SkipUI to take advantage of Compose's UI state mechanisms in
136
152
137
153
## composeModifier
138
154
139
-
In addition to `ComposeView` above, SkipUI offers the `composeModifier` SwiftUI modifier. This modifier allows you to apply any Compose modifiers to the underlying Compose view. It takes a block that accepts a single `androidx.compose.ui.Modifier` parameter and returns a `Modifier` as well. For example:
155
+
In addition to `ComposeView` above, SkipUI offers the `composeModifier` SwiftUI modifier. This modifier allows you to apply any Compose modifiers to the underlying Compose view.
156
+
157
+
### Skip Fuse
158
+
159
+
Using `composeModifier` from Skip Fuse is much like using `ComposeView`:
160
+
161
+
1. Define a `ContentModifier` in a transpiled `#if SKIP` block.
162
+
1. Use `.composeModifier` to apply the `ContentModifier ` to the target SwiftUI view.
163
+
164
+
Within your `ContentModifier`, apply any SkipUI modifiers to the given target view. This includes the [Material](#material) modifiers we describe below, or the same-named transpiled `composeModifier`, which takes a block that accepts a single `androidx.compose.ui.Modifier` parameter and returns a `Modifier` as well. The following example applies Compose's `imePadding` modifier our SwiftUI on Android:
The `ContentModfiier` protocol consists of a single function:
190
+
191
+
```swift
192
+
publicprotocolContentModifier {
193
+
funcmodify(view: any View) ->any View
194
+
}
195
+
```
196
+
197
+
### Skip Lite
198
+
199
+
If you are writing your SwiftUI using Skip Lite, you don't need to define a `ContentModfifier`. You can apply [Material](#material) modifiers or `.composeModifier` directly:
Like `ComposeView`, the `composeModifier` function is only available in Android, so you must guard all uses with the `#if SKIP` compiler directives.
156
-
157
-
`composeModifier` is currently only available for Skip Lite transpiled Swift.
158
-
{: class="callout info"}
159
-
160
214
## Material
161
215
162
216
Under the hood, SkipUI uses Android's Material 3 colors and components. While we expect you to use SwiftUI's built-in color schemes (`.preferredColorScheme`) and modifiers (`.background`, `.foregroundStyle`, `.tint`, and so on) for most UI styling, there are some Android customizations that have no SwiftUI equivalent. Skip therefore adds additional, Android-only API for manipulating Material colors and components.
@@ -184,7 +238,30 @@ internal fun PresentationRootView(context: ComposeContext) {
184
238
}
185
239
```
186
240
187
-
Skip also provides the SwiftUI `.material3ColorScheme(_:)` modifier to customize a SwiftUI view hierarchy. The modifier takes the same closure as the `Material3ColorScheme` Kotlin function. It is only available for Android, so you must use it within a `#if SKIP` block. For example:
241
+
Skip also provides the SwiftUI `.material3ColorScheme(_:)` modifier to customize a SwiftUI view hierarchy. The modifier takes the same closure as the `Material3ColorScheme` Kotlin function. Apply this modifier using the `.composeModifier` techniques discussed in the previous section. For example:
@@ -203,9 +280,6 @@ Skip's built-in components use the following Material 3 colors, if you'd like to
203
280
-`outline`
204
281
-`outlineVariant`
205
282
206
-
The `material3ColorScheme` modifier is currently only available for Skip Lite transpiled Swift.
207
-
{: class="callout info"}
208
-
209
283
### Material Components
210
284
211
285
In addition to the `.material3ColorScheme` modifier detailed above, Skip includes many other `.material3` modifiers for its underlying Material 3 components. This family of modifiers share a common API pattern:
@@ -215,11 +289,37 @@ In addition to the `.material3ColorScheme` modifier detailed above, Skip include
215
289
- The modifiers place your closure into the SwiftUI `Environment`. This means that you can apply the modifier on a root view, and it will affect all subviews. While you may be used to placing navigation and tab bar modifiers on the views *within* the `NavigationStack` or `TabView`, the `.material3` family of modifiers always go *on or outside* the views you want to affect.
216
290
- Because they are designed to reach beneath Skip's SwiftUI covers, the modifiers use Compose terminology and types. In fact the properties of the supplied `Material3<Component>Options` structs typically exactly match the corresponding `androidx.compose.material3` component function parameters.
217
291
218
-
You can find details on Material 3 component API in [this Android API documentation](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary). All `material3` modifiers are currently only available for Skip Lite transpiled Swift.
292
+
You can find details on Material 3 component API in [this Android API documentation](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary).
219
293
{: class="callout info"}
220
294
221
295
Here is an example of changing the selected indicator color on your Android tab bar, which is implemented by the Material 3 `NavigationBar` component:
222
296
297
+
Skip Fuse:
298
+
299
+
```swift
300
+
TabView {
301
+
...
302
+
}
303
+
#ifos(Android)
304
+
.composeModifier { NavigationBarModifier() }
305
+
#endif
306
+
307
+
...
308
+
309
+
#if SKIP
310
+
structNavigationBarModifier : ContentModifier {
311
+
funcmodify(view: any View) ->any View {
312
+
view.material3NavigationBar { options in
313
+
let updatedColors = options.itemColors.copy(selectedIndicatorColor: Color.green.asComposeColor())
314
+
return options.copy(itemColors: updatedColors)
315
+
}
316
+
}
317
+
}
318
+
#endif
319
+
```
320
+
321
+
Skip Lite:
322
+
223
323
```swift
224
324
TabView {
225
325
...
@@ -371,11 +471,11 @@ public struct Material3TopAppBarOptions {
371
471
}
372
472
```
373
473
374
-
Note that `.material3TopAppBar` involves API that Compose deems experimental, so you must add the following to any `View` where you use it:
474
+
Note that `.material3TopAppBar` involves API that Compose deems experimental, so you must add the following to any Skip Fuse `ContentModfifier` or Skip Lite `View` where you use it:
0 commit comments