Using KMP and CMP in many projects recently and ve...
# compose-ios
m
Using KMP and CMP in many projects recently and very pleased with how far it came. Thx for the great work Jetbrains team! 👏🏽 🔥 Since I’m kind of a perfectionist when it comes to UI/UX and also a iOS user, i pay close attention to where Swift UI gives (atm) a superior UX, and I’m thinking how to change that in the future, so my CMP apps are indistinguishable from Swift apps. Here are my current 2 points that I feel CMP lacks on iOS. Maybe it can be addressed in an official way from Jetbrains? 1) Context menu I enjoy as ios User to be able to play around with Apple’s attention to detail when it comes to Ui elements. Like for context menus, you can swipe up and down, feel the haptic feedback, and have nesting animations, overall just a great UI. Could there be a bridge so we can show native context menus over CMP components? I think this would be of great use. Will try to build sth like this soon myself. Screenshot attached from a context menu. 2) Swipe back navigation We need swipe back navigation on iOS. There are community solutions but i think there should be an official way for CMP, it would add one of the last elements to CMP before i’d call it close to perfect.
⬆️ 5
f
Compose-ios really needs to have an iOS look&feel. Currently it focused on material. So wait and see.
a
Hi @Max, many thanks! Regarding context menu - unfortunately only UIControls are able to present such element. Here I would only recommend to mimic the same behaviour using Compose. Maybe some opensource solutions are already available? Depending on what you're meaning by the back navigation, there are 2 answers: • There is a known issue with native swipe back navigation, but there is a workaround - to handle
UIGestureRecognizerDelegate
and deprioritize the
CMPGestureRecognizer
. • Compose BackHandler is a highly-demanded feature. We're working on it.
👍 3
f
@Max Someone made a project (unstable) but proving its possible https://github.com/alexzhirkevich/compose-cupertino
âž• 3
a
Why not hook into native APIs for something like this?
h
@Andrei Salavei where can we see the workaround or a fix is needed for it to work, kinda confused, care to share more? Using CMP for iOS at the moment and I feel like not providing swipe back for navigating up on that platform is a really bad UX, at least a callback swipe function that will enable me to call navHostController.navigateUp is enough for me in a CMP code sharing the UI.
h
Copy code
fun MainViewController(
    onAppInitialized: (() -> Unit)? = null
) = ComposeUIViewController(
    configure = {
        onFocusBehavior = OnFocusBehavior.DoNothing
    }
) {
    CMPApp(
        onAppInitialized = onAppInitialized
    )
}
Sorry for the dumb question but my use case is different i guess, or we’re talking about 2 different things. How do I do this in this simple code, what i want to do is to enable the “swipe back gesture” navigation, i can manually call navigate to
GlobalNavController.navigateUp
i just want to have the swipe back functionality baked in with some callback and i’ve no idea how to achieve it in this current setup
a
Am I right, that your app is a single view controller app, which is MainViewController and you want to detect swipe back gesture?
h
yes
a
Okay that's not an easy topic. Quick answer is here. Just add it to MainViewController.view and see the result. However there is no simple answer how to make everything work as you want. You have to know that gesture recognizers work on top of UIKit touches system and they will overtake similar gestures from your Compose app. Also it may spoil work of the
CMPGestureRecognizer
. To adjust the behaviour, you can use the
UIGestureRecognizerDelegate
to configure priority or feedback of your gesture recognizer.
h
As someone who's never worked with iOS before I don't even know from where to start 🥲 guess there's many things you need to know in order to make this work. I saw this very simple because the code above drives my whole app and it just lives in one file
Copy code
struct ComposeView: UIViewControllerRepresentable {
    var onAppInitialized: (() -> Void)?
    func makeUIViewController(context: Context) -> UIViewController {
        MainViewControllerKt.MainViewController(
            onAppInitialized: onAppInitialized
        )
    }
    
    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}


struct ContentView: View {
    
    var body: some View {
        ZStack {
            Color(.surface)
            ComposeView(onAppInitialized: {
                
                }
            })
}
}
Copy code
@main
struct iOSApp: App {
    
    
    
    init() {
        
        MainViewControllerKt.initialiseDependencies()
       
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
a
@Hristijan, I tried to implement the solution but with no success. Need to investigate it deeper. Please check aforementioned issues status.
thank you color 1