Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Compose Multiplatform] License screen can now be opened. #820

Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ import platform.UIKit.UIApplication
import platform.UIKit.UIViewController
import platform.darwin.NSObject

private object ExternalNavControllerLink {
var onLicenseScreenRequest: (() -> Unit)? = null
}
Comment on lines +82 to +84
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this implementation very much. 🤔
If there is a better way to implement it, we will follow it. 🫡


@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Suppress("UNUSED")
fun kaigiAppController(
repositories: Repositories,
onLicenseScreenRequest: () -> Unit,
): UIViewController = ComposeUIViewController {
ExternalNavControllerLink.onLicenseScreenRequest = onLicenseScreenRequest

CompositionLocalProvider(
LocalRepositories provides repositories.map
) {
Expand Down Expand Up @@ -207,7 +214,7 @@ private fun NavGraphBuilder.mainScreen(
}

AboutItem.Contributors -> navController.navigate(contributorsScreenRoute)
AboutItem.License -> {} //externalNavController.navigateToLicenseScreen()
AboutItem.License -> externalNavController.navigateToLicenseScreen()
AboutItem.Medium -> externalNavController.navigate(
url = "https://medium.com/droidkaigi",
)
Expand Down Expand Up @@ -295,6 +302,10 @@ private class ExternalNavController(
UIApplication.sharedApplication.openURL(nsUrl)
}

fun navigateToLicenseScreen() {
ExternalNavControllerLink.onLicenseScreenRequest?.invoke()
}

/**
* Navigate to Calendar Registration
*/
Expand Down
3 changes: 2 additions & 1 deletion app-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ let package = Package(
.firebaseAuth,
.firebaseRemoteConfig,
.tca,
.model
.model,
.licenseList,
]
),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import LicenseList
@preconcurrency import shared

public struct KmpAppComposeViewControllerWrapper: UIViewControllerRepresentable {
Expand All @@ -8,10 +9,23 @@ public struct KmpAppComposeViewControllerWrapper: UIViewControllerRepresentable
let container = Container.shared
let repositories: any Repositories = container.get(type: (any Repositories).self)
return IosComposeKaigiAppKt.kaigiAppController(
repositories: repositories
repositories: repositories,
onLicenseScreenRequest: {
openLicenseScreen()
}
)
}

public func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}

private func openLicenseScreen() {
if let windowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
if let rootViewController = windowScene.windows.first?.rootViewController {
let licenseView = LicenseListView()
let hostingController = UIHostingController(rootView: licenseView)
rootViewController.present(hostingController, animated: true, completion: nil)
}
}
}
}
Loading