App-local SwiftUI
+One player, two renderers
+Now Playing demonstrates how your Web UI can become a native SwiftUI view, using the same state and actions.
+1. Try Now Playing
+Extension: {{ demo.enabled() ? 'Enabled' : 'Disabled' }}
+Off: Web. On: SwiftUI on supported iOS; Web elsewhere. Ordinary tabs and Duo Mode both work.
+-
+
- Use the player at the bottom to pause or resume. +
- Switch the toggle. Playback state stays the same. +
- Tap the track or swipe up to open the Web modal. Close it using the button at the top left. +
UI demo only. No audio is played.
+2. Shared state and actions
+-
+
- Web owns the state +
data-title,data-artistanddata-playingsupply both renderers.
+ - SwiftUI sends actions back +
- Play and open activate the original Web actions. The app updates its state and attributes. +
- Layout stays with the app +
- This example uses element projection: SwiftUI follows the Web element's position and size. +
3. Build your own
+Keep the Web renderer, DOM reader and SwiftUI view in your project. No separate npm package or Capacitor plugin is needed.
+-
+
- Read your element with
defineNativeUI().
+ - Register the matching view with
NativeUIShell.register().
+ - Pass the definition to
enableNativeUIShell().
+
+ tab-accessory is an optional placement chosen by your app. This example uses the default
+ element placement.
+