Skip to content

Commit

Permalink
Hamburger nav fix
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Mar 6, 2024
1 parent ca5dcf9 commit 6fee403
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ value class ExternalLink(override val native: NExternalLink) : RView<NExternalLi
expect fun ViewWriter.externalLinkActual(setup: ExternalLink.()->Unit = {}): 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
expect var ExternalLink.newTab: Boolean
expect fun ExternalLink.onNavigate(action: suspend () -> Unit)
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ value class Link(override val native: NLink) : RView<NLink>
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
expect var Link.newTab: Boolean
expect fun Link.onNavigate(action: suspend () -> Unit)
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import com.lightningkite.rock.views.*
import com.lightningkite.rock.views.direct.*


fun ViewWriter.navGroupColumn(elements: Readable<List<NavElement>>, setup: ContainingView.()->Unit = {}) {
fun ViewWriter.navGroupColumn(elements: Readable<List<NavElement>>, onNavigate: suspend ()->Unit = {}, setup: ContainingView.()->Unit = {}) {
col {
navGroupColumnInner(elements)
navGroupColumnInner(elements, onNavigate)
setup()
}
}
private fun ViewWriter.navGroupColumnInner(readable: Readable<List<NavElement>>) {
private fun ViewWriter.navGroupColumnInner(readable: Readable<List<NavElement>>, onNavigate: suspend ()->Unit = {}) {
forEach(readable) {
fun ViewWriter.display(navElement: NavElement) {
row {
Expand All @@ -31,6 +31,7 @@ private fun ViewWriter.navGroupColumnInner(readable: Readable<List<NavElement>>)
is NavExternal -> externalLink {
::to { it.to() }
display(it)
this.onNavigate(onNavigate)
}

is NavGroup -> {
Expand Down Expand Up @@ -58,6 +59,7 @@ private fun ViewWriter.navGroupColumnInner(readable: Readable<List<NavElement>>)
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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,4 +25,7 @@ actual inline var ExternalLink.newTab: Boolean
get() = native.newTab
set(value) {
native.newTab = value
}
}
actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit {
native.onNavigate = action
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ actual inline var Link.newTab: Boolean
get() = native.newTab
set(value) {
native.newTab = value
}
}
actual fun Link.onNavigate(action: suspend () -> Unit): Unit {
native.onNavigate = action
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -23,4 +25,9 @@ actual inline var ExternalLink.newTab: Boolean
get() = native.target == "_blank"
set(value) {
native.target = if (value) "_blank" else "_self"
}
}
actual fun ExternalLink.onNavigate(action: suspend () -> Unit): Unit {
native.onclick = {
calculationContext.launchManualCancel(action)
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
}
}
actual fun Link.onNavigate(action: suspend () -> Unit): Unit {
native.asDynamic().__ROCK__onNavigate = action
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 6fee403

Please sign in to comment.