diff --git a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.android.kt b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.android.kt index 7adee3a1..22d143a1 100644 --- a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.android.kt +++ b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.android.kt @@ -3,12 +3,14 @@ package com.lightningkite.rock.views.direct import android.content.Intent import android.net.Uri import android.widget.FrameLayout +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.views.ViewDsl import com.lightningkite.rock.views.ViewWriter +import com.lightningkite.rock.views.calculationContext import java.util.* @Suppress("ACTUAL_WITHOUT_EXPECT") -actual typealias NExternalLink = SlightlyModifiedFrameLayout +actual typealias NExternalLink = LinkFrameLayout actual var ExternalLink.to: String get() { @@ -20,6 +22,7 @@ actual var ExternalLink.to: String val url = if(!value.startsWith("http")) "http://$value" else value val temp = Intent(Intent.ACTION_VIEW, Uri.parse(url)) view.context.startActivity(temp) + calculationContext.launchManualCancel { native.onNavigate() } // val intent = Intent().apply { // action = Intent.ACTION_VIEW // categories?.add(Intent.CATEGORY_APP_BROWSER) @@ -37,8 +40,11 @@ actual var ExternalLink.newTab: Boolean set(value) { native.tag = value } +actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit { + native.onNavigate = action +} @ViewDsl actual inline fun ViewWriter.externalLinkActual(crossinline setup: ExternalLink.() -> Unit) { - viewElement(factory = ::SlightlyModifiedFrameLayout, wrapper = ::ExternalLink, setup = setup) + viewElement(factory = ::LinkFrameLayout, wrapper = ::ExternalLink, setup = setup) } \ No newline at end of file diff --git a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/Link.android.kt b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/Link.android.kt index 1f7517fc..ef607b5e 100644 --- a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/Link.android.kt +++ b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/Link.android.kt @@ -1,11 +1,13 @@ package com.lightningkite.rock.views.direct import com.lightningkite.rock.RockActivity +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.navigation.PlatformNavigator import com.lightningkite.rock.navigation.RockScreen import com.lightningkite.rock.reactive.await import com.lightningkite.rock.views.ViewDsl import com.lightningkite.rock.views.ViewWriter +import com.lightningkite.rock.views.calculationContext import com.lightningkite.rock.views.navigator import kotlinx.coroutines.runBlocking import timber.log.Timber @@ -14,16 +16,11 @@ import timber.log.Timber actual typealias NLink = LinkFrameLayout actual var Link.to: RockScreen - get() { - val rockScreen: RockScreen - runBlocking { - rockScreen = PlatformNavigator.currentScreen.await()!! - } - return rockScreen - } + get() = TODO() set(value) { native.setOnClickListener { native.navigator.navigate(value) + calculationContext.launchManualCancel { native.onNavigate() } } } actual var Link.newTab: Boolean @@ -33,6 +30,9 @@ actual var Link.newTab: Boolean set(value) { Timber.d("New Tab called with value $value") } +actual fun Link.onNavigate(action: suspend () -> Unit): Unit { + native.onNavigate = action +} @ViewDsl actual inline fun ViewWriter.linkActual(crossinline setup: Link.() -> Unit) { diff --git a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/subclasses.kt b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/subclasses.kt index a1fec724..0c95ee5b 100644 --- a/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/subclasses.kt +++ b/library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/subclasses.kt @@ -10,6 +10,7 @@ import com.lightningkite.rock.views.animationsEnabled class LinkFrameLayout(context: Context): SlightlyModifiedFrameLayout(context) { lateinit var navigator: RockNavigator + var onNavigate: suspend ()->Unit = {} } class RockLayoutTransition: LayoutTransition() { diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.kt index de5c83cf..9213dc1a 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.kt @@ -16,4 +16,5 @@ value class ExternalLink(override val native: NExternalLink) : RViewUnit = {}): Unit @OptIn(ExperimentalContracts::class) @ViewDsl inline fun ViewWriter.externalLink(noinline setup: ExternalLink.() -> Unit = {}) { contract { callsInPlace(setup, InvocationKind.EXACTLY_ONCE) }; externalLinkActual(setup) } expect var ExternalLink.to: String -expect var ExternalLink.newTab: Boolean \ No newline at end of file +expect var ExternalLink.newTab: Boolean +expect fun ExternalLink.onNavigate(action: suspend () -> Unit) diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/Link.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/Link.kt index 8d953ffa..e4de8fe3 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/Link.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/Link.kt @@ -17,4 +17,5 @@ value class Link(override val native: NLink) : RView expect fun ViewWriter.linkActual(setup: Link.()->Unit = {}): Unit @OptIn(ExperimentalContracts::class) @ViewDsl inline fun ViewWriter.link(noinline setup: Link.() -> Unit = {}) { contract { callsInPlace(setup, InvocationKind.EXACTLY_ONCE) }; linkActual(setup) } expect var Link.to: RockScreen -expect var Link.newTab: Boolean \ No newline at end of file +expect var Link.newTab: Boolean +expect fun Link.onNavigate(action: suspend () -> Unit) diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/AppNav.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/AppNav.kt index 7afe83ac..a1e29dce 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/AppNav.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/AppNav.kt @@ -89,11 +89,14 @@ fun ViewWriter.appNavHamburger(setup: AppNav.() -> Unit) { expanding - stack { navigatorView(navigator) row { + ignoreInteraction = true onlyWhen(false) { showMenu.await() && appNav.existsProperty.await() } - scrolls - bar - navGroupColumn(appNav.navItemsProperty) { + scrolls - bar - navGroupColumn(appNav.navItemsProperty, { showMenu set false }) { spacing = 0.px } - weight(2f) - space() + weight(2f) - space { + ignoreInteraction = true + } } } } diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/navComponents.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/navComponents.kt index 5bf0a6bc..e250c44d 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/navComponents.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/views/l2/navComponents.kt @@ -7,13 +7,13 @@ import com.lightningkite.rock.views.* import com.lightningkite.rock.views.direct.* -fun ViewWriter.navGroupColumn(elements: Readable>, setup: ContainingView.()->Unit = {}) { +fun ViewWriter.navGroupColumn(elements: Readable>, onNavigate: suspend ()->Unit = {}, setup: ContainingView.()->Unit = {}) { col { - navGroupColumnInner(elements) + navGroupColumnInner(elements, onNavigate) setup() } } -private fun ViewWriter.navGroupColumnInner(readable: Readable>) { +private fun ViewWriter.navGroupColumnInner(readable: Readable>, onNavigate: suspend ()->Unit = {}) { forEach(readable) { fun ViewWriter.display(navElement: NavElement) { row { @@ -31,6 +31,7 @@ private fun ViewWriter.navGroupColumnInner(readable: Readable>) is NavExternal -> externalLink { ::to { it.to() } display(it) + this.onNavigate(onNavigate) } is NavGroup -> { @@ -58,6 +59,7 @@ private fun ViewWriter.navGroupColumnInner(readable: Readable>) is NavLink -> link { ::to { it.destination() } display(it) + this.onNavigate(onNavigate) } in maybeThemeFromLast { existing -> if (navigator.currentScreen.await() ?.let { navigator.routes.render(it) } == navigator.routes.render(it.destination()) diff --git a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.ios.kt b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.ios.kt index 7aa1653e..9a0b9832 100644 --- a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.ios.kt +++ b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.ios.kt @@ -1,7 +1,10 @@ package com.lightningkite.rock.views.direct +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.views.ViewDsl import com.lightningkite.rock.views.ViewWriter +import com.lightningkite.rock.views.calculationContext +import platform.UIKit.UIControlEventTouchUpInside @Suppress("ACTUAL_WITHOUT_EXPECT") actual typealias NExternalLink = NativeLink @@ -22,4 +25,7 @@ actual inline var ExternalLink.newTab: Boolean get() = native.newTab set(value) { native.newTab = value - } \ No newline at end of file + } +actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit { + native.onNavigate = action +} \ No newline at end of file diff --git a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/Link.ios.kt b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/Link.ios.kt index 418c8c60..b9dfcba9 100644 --- a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/Link.ios.kt +++ b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/Link.ios.kt @@ -25,4 +25,7 @@ actual inline var Link.newTab: Boolean get() = native.newTab set(value) { native.newTab = value - } \ No newline at end of file + } +actual fun Link.onNavigate(action: suspend () -> Unit): Unit { + native.onNavigate = action +} \ No newline at end of file diff --git a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/NativeLink.kt b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/NativeLink.kt index 4a2ddda8..d3eef7cd 100644 --- a/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/NativeLink.kt +++ b/library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/NativeLink.kt @@ -2,6 +2,8 @@ package com.lightningkite.rock.views.direct +import com.lightningkite.rock.launchGlobal +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.models.Align import com.lightningkite.rock.models.SizeConstraints import com.lightningkite.rock.navigation.RockNavigator @@ -50,6 +52,7 @@ class NativeLink: UIButton(CGRectZero.readValue()), UIViewWithSizeOverridesProto var onNavigator: RockNavigator? = null var toUrl: String? = null var newTab: Boolean = false + var onNavigate: suspend ()->Unit = {} init { addTarget(this, sel_registerName("clicked"), UIControlEventTouchUpInside) @@ -58,6 +61,7 @@ class NativeLink: UIButton(CGRectZero.readValue()), UIViewWithSizeOverridesProto @ObjCAction fun clicked() { toScreen?.let { onNavigator?.navigate(it) } toUrl?.let { UIApplication.sharedApplication.openURL(NSURL(string = it)) } + calculationContext.launchManualCancel(onNavigate) } } \ No newline at end of file diff --git a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.js.kt b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.js.kt index 5626a49e..09c90c70 100644 --- a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.js.kt +++ b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ExternalLink.js.kt @@ -1,7 +1,9 @@ package com.lightningkite.rock.views.direct +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.views.ViewDsl import com.lightningkite.rock.views.ViewWriter +import com.lightningkite.rock.views.calculationContext import org.w3c.dom.HTMLAnchorElement @Suppress("ACTUAL_WITHOUT_EXPECT") @@ -23,4 +25,9 @@ actual inline var ExternalLink.newTab: Boolean get() = native.target == "_blank" set(value) { native.target = if (value) "_blank" else "_self" - } \ No newline at end of file + } +actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit { + native.onclick = { + calculationContext.launchManualCancel(action) + } +} \ No newline at end of file diff --git a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/Link.js.kt b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/Link.js.kt index ab8edbf1..fb577e23 100644 --- a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/Link.js.kt +++ b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/Link.js.kt @@ -1,11 +1,13 @@ package com.lightningkite.rock.views.direct +import com.lightningkite.rock.launchManualCancel import com.lightningkite.rock.navigation.PlatformNavigator import com.lightningkite.rock.navigation.RockNavigator import com.lightningkite.rock.navigation.RockScreen import com.lightningkite.rock.navigation.render import com.lightningkite.rock.views.ViewDsl import com.lightningkite.rock.views.ViewWriter +import com.lightningkite.rock.views.calculationContext import com.lightningkite.rock.views.navigator import org.w3c.dom.HTMLAnchorElement @@ -30,10 +32,17 @@ actual inline var Link.to: RockScreen native.onclick = { it.preventDefault() navigator.navigate(value) + (native.asDynamic().__ROCK__onNavigate as? suspend ()->Unit)?.let { + println("launchingmanucan") + calculationContext.launchManualCancel(it) + } } } actual inline var Link.newTab: Boolean get() = native.target == "_blank" set(value) { native.target = if (value) "_blank" else "_self" - } \ No newline at end of file + } +actual fun Link.onNavigate(action: suspend () -> Unit): Unit { + native.asDynamic().__ROCK__onNavigate = action +} \ No newline at end of file diff --git a/library/src/jvmMain/kotlin/com/lightningkite/rock/views/direct/generated.jvm.kt b/library/src/jvmMain/kotlin/com/lightningkite/rock/views/direct/generated.jvm.kt index 6a80e8a2..9937302a 100644 --- a/library/src/jvmMain/kotlin/com/lightningkite/rock/views/direct/generated.jvm.kt +++ b/library/src/jvmMain/kotlin/com/lightningkite/rock/views/direct/generated.jvm.kt @@ -25,6 +25,7 @@ actual inline var Link.to: RockScreen actual inline var Link.newTab: Boolean get() = TODO() set(value) { } +actual fun Link.onNavigate(action: suspend () -> Unit): Unit {} @Suppress("ACTUAL_WITHOUT_EXPECT") actual typealias NExternalLink = HTMLElement @ViewDsl actual inline fun ViewWriter.externalLinkActual(crossinline setup: ExternalLink.() -> Unit): Unit = todo("externalLink") @@ -34,6 +35,7 @@ actual inline var ExternalLink.to: String actual inline var ExternalLink.newTab: Boolean get() = TODO() set(value) { } +actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit {} @Suppress("ACTUAL_WITHOUT_EXPECT") actual typealias NImageView = HTMLElement @ViewDsl actual inline fun ViewWriter.imageActual(crossinline setup: ImageView.() -> Unit): Unit = todo("image")