ziv kesten
11/15/2024, 7:27 AMShowNativeText
view in the example project with a simple scrollable list, but it does not respond to the scroll gesture on the simulator:
struct SimpleTextView : View {
@ObservedObject var observable: ComposeApp.ShowNativeTextObservable
let items = Array(1...100).map { "Item \($0)" }
var body: some View {
NavigationStack {
List(items, id: \.self) { item in
Text(item)
}
.navigationTitle("Scrollable List")
}
}
}
Is there a known issue with gestures or am i missing some bindings?Hugo Bernardi
11/15/2024, 7:45 AMUIKitView
, the following API (UIKitInteropProperties
) has been introduced to fix a similar issue in Compose :
UIKitView(
factory = { myView()},
modifier = modifier,
properties = UIKitInteropProperties(interactionMode = UIKitInteropInteractionMode.NonCooperative),
)
By default, it is set to Cooperative
. Maybe there is a similar configuration to do with the bridge ?ziv kesten
11/15/2024, 8:08 AMUIScrollView
. When the touch is first detected, there is a short delay (150 ms) that lets the app decide whether to make the container aware of it:
And realized that i have to click, hold 150ms, than it works....ziv kesten
11/15/2024, 8:18 AMkpgalligan
11/15/2024, 7:29 PMon aThe bridge calls, the following API (UIKitView
) has been introduced to fix a similar issue in ComposeUIKitInteropProperties
UIKitView
under the hood, and looking at the generated code, the version it calls is deprecated and should be updated to the one you posted.
What the bridge does is let you write this in Kotlin
@ExpectSwiftView(
type = ViewType.UIView
)
@Composable
expect fun MapViewWithUiView(
modifier: Modifier = Modifier,
coordinate: MapCoordinates,
title: String,
)
The in iOS (if using UIKit) you can write something like this:
class NativeMapUIKitView: UIView, MapViewWithUiViewDelegate {
private var mapView: MKMapView!
private var annotation = MKPointAnnotation()
init(title: String, coordinate: MapCoordinates, frame: CGRect = .zero) {
super.init(frame: frame)
setupMapView(title: title, coordinate: coordinate) // Does iOS Stuff
}
// iOS Code
// MARK: - MapViewWithUiViewDelegate
func updateCoordinate(coordinate: MapCoordinates) {
// Triggered from Composable
}
func updateTitle(title: String) {
// Triggered from Composable
}
}
The arguments to the Composable, not including Modifier
, get wired into update*
calls when values change.
Not sure why I put the UIKit example first, but SwiftUI is similar:
@ExpectSwiftView(
type = ViewType.SwiftUI
)
@Composable
expect fun MapViewWithSwiftUI(
modifier: Modifier = Modifier,
coordinate: MapCoordinates,
title: String,
callback: (String) -> Unit
)
Then in Swift:
class SwiftUINativeViewFactory : NativeViewFactory {
// Etc
// This function implements one of the functions from the generated NativeViewFactory
func createMapViewWithSwiftUI(observable: ComposeApp.MapViewWithSwiftUIObservable) -> AnyView {
return AnyView(NativeMapViewBindingSwiftUI(observable: observable))
}
// Etc
}
struct NativeMapViewBindingSwiftUI : View {
@ObservedObject var observable: MapViewWithSwiftUIObservable
var body: some View {
NativeMapView(title: observable.title, coordinate: observable.coordinate)
}
}
The class MapViewWithSwiftUIObservable
is generated and has the params from the Composable (again, minus Modifier
).
The idea is that everything you'd need to do in between to get updates from the Composable into a form that is usable from Swift is generated, so you (mostly) just need to implement the iOS UI code.kpgalligan
11/15/2024, 7:32 PMkpgalligan
11/15/2024, 7:34 PMziv kesten
11/17/2024, 7:02 AMcooperative
or non-cooperative
parameter to the NativeViewFactory
function?SrSouza
11/19/2024, 3:19 PMmodifier: Modifier,
factory: () -> UIViewController
ziv kesten
01/08/2025, 7:44 AMDefaultDelayMillis
as the constructor only takes a true/false which will lead to Cooperative/NonCoopertive modes
So the basic problem of the 150 millis delay still exists for me.
Is there any way to resolve this?