Emits events and requests size updates for a hosted element.
| 53 | |
| 54 | /// Emits events and requests size updates for a hosted element. |
| 55 | @MainActor |
| 56 | public final class EffectUIContext { |
| 57 | private let send: (String, [String: Any]) -> Void |
| 58 | private let resize: () -> Void |
| 59 | |
| 60 | init(emit: @escaping (String, [String: Any]) -> Void, invalidateSize: @escaping () -> Void) { |
| 61 | send = emit |
| 62 | resize = invalidateSize |
| 63 | } |
| 64 | |
| 65 | /// Fires the handler bound to `name`. Payload values must be JSON-compatible. |
| 66 | public func emit(_ name: String, _ payload: [String: Any] = [:]) { |
| 67 | send(name, payload) |
| 68 | } |
| 69 | |
| 70 | /// Rereads `intrinsicContentSize` and updates layout if the size changed. |
| 71 | /// Explicit style dimensions still take precedence. |
| 72 | public func invalidateSize() { |
| 73 | resize() |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /// Registers native views that JS renders with `Native.hostedView`. |
| 78 | @MainActor |