Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/version-3' into version-3
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Dec 4, 2024
2 parents 5fbcdb7 + 7228b46 commit e98f21b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object RootScreen : Screen {
}
} in card

linkScreen { ScrollIntoViewTest }
linkScreen { FormattedInputTests() }
linkScreen { TestingGroundScreen }
linkScreen { ListEditScreen }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.lightningkite.mppexampleapp.internal

import com.lightningkite.kiteui.Routable
import com.lightningkite.kiteui.models.Align
import com.lightningkite.kiteui.models.rem
import com.lightningkite.kiteui.navigation.Screen
import com.lightningkite.kiteui.reactive.Property
import com.lightningkite.kiteui.reactive.reactive
import com.lightningkite.kiteui.views.ViewWriter
import com.lightningkite.kiteui.views.centered
import com.lightningkite.kiteui.views.direct.*
import com.lightningkite.kiteui.views.expanding
import com.lightningkite.kiteui.views.important

@Routable("internal/scroll-into-view-test")
object ScrollIntoViewTest : Screen {

enum class Location { Top, Bottom }
val jumpTo = Property<Location?>(null)

override fun ViewWriter.render() {
scrolls - stack {
sizeConstraints(height = 500.rem) - col {
centered - important - button {
reactive {
if (jumpTo() == Location.Top) {
this@button.scrollIntoView(horizontal = null, vertical = Align.Start, animate = true)
jumpTo.value = null
}
println("Finished Check")
}
text("Scroll To Bottom")
onClick { jumpTo.value = Location.Bottom }
}
expanding - space()
centered - important - button {
reactive {
if (jumpTo() == Location.Bottom) {
this@button.scrollIntoView(horizontal = null, vertical = Align.Start, animate = true)
jumpTo.value = null
}
println("Finished Check")
}
text("Scroll To Top")
onClick { jumpTo.value = Location.Top }
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import kotlinx.dom.addClass
import kotlinx.dom.createElement
import kotlinx.dom.hasClass
import kotlinx.dom.removeClass
import org.w3c.dom.Element
import org.w3c.dom.HTMLElement
import org.w3c.dom.get
import org.w3c.dom.*
import org.w3c.dom.svg.SVGElement
import kotlin.js.Json
import kotlin.js.json
Expand Down Expand Up @@ -264,11 +262,26 @@ actual class FutureElement actual constructor() {
actual class FutureElementStyle(var native: dynamic)
actual class FutureElementAttributes(var native: dynamic)

fun Align?.logicalPosition(): ScrollLogicalPosition = when (this) {
Align.Start -> ScrollLogicalPosition.START
Align.Center -> ScrollLogicalPosition.CENTER
Align.End -> ScrollLogicalPosition.END

Align.Stretch -> ScrollLogicalPosition.START
null -> ScrollLogicalPosition.START
}
actual fun RView.nativeScrollIntoView(
horizontal: Align?,
vertical: Align?,
animate: Boolean
) {
native.element?.scrollIntoView(
ScrollIntoViewOptions(
block = vertical.logicalPosition(),
inline = horizontal.logicalPosition(),
behavior = if (animate) ScrollBehavior.SMOOTH else ScrollBehavior.INSTANT
)
)
}

@Suppress("NOTHING_TO_INLINE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ actual fun RView.nativeScrollIntoView(
vertical: Align?,
animate: Boolean
) {

}

0 comments on commit e98f21b

Please sign in to comment.