Skip to content

Commit

Permalink
Major iOS improvements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Mar 26, 2024
1 parent 05d80e6 commit b4bb98c
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.lightningkite.mppexampleapp

import com.lightningkite.rock.*
import com.lightningkite.rock.models.Align
import com.lightningkite.rock.models.SizeConstraints
import com.lightningkite.rock.models.px
import com.lightningkite.rock.models.rem
import com.lightningkite.rock.navigation.RockScreen
import com.lightningkite.rock.reactive.*
import com.lightningkite.rock.views.*
import com.lightningkite.rock.views.direct.*
import com.lightningkite.rock.views.l2.lazyExpanding

@Routable("recycler-view/horizontal")
object HorizontalRecyclerViewScreen : RockScreen {
override val title: Readable<String>
get() = super.title

override fun ViewWriter.render() {
var expanded = Property(-1)
val items = Property((1..101).toList())
var recyclerView: RecyclerView? = null
col {
row {
for(align in Align.values()) {
expanding - button {
subtext("Jump ${align.name}")
onClick { recyclerView?.scrollToIndex(49, align, false) }
}
}
}
row {
for(align in Align.values()) {
expanding - button {
subtext("Scroll ${align.name}")
onClick { recyclerView?.scrollToIndex(49, align, true) }
}
}
}
row {
repeat(4) {
val cols = it + 1
expanding - button {
subtext("${cols} columns")
onClick { recyclerView?.columns = cols }
}
}
}
horizontalRecyclerView {
recyclerView = this
spacing = 0.5.rem
columns = 2
this.scrollToIndex(10, Align.Start)
children(items) {
themeFromLast { theme ->
if(it.await() == 50) theme.important() else if(it.await() % 7 == 0) theme.hover() else theme
} - col {
row {
expanding - centered - text { ::content { "Item ${it.await()}" } }
centered - button {
text {
::content { if (expanded.await() == it.await()) "Expanded" else "Expand" }
}
onClick {
expanded.value = if(it.await() == expanded.value) -1 else it.await()
native.scrollIntoView(null, Align.Start, true)
}
}
}
lazyExpanding(shared { expanded.await() == it.await() }) {
row {
text("More Content")
}
}
}
}
} in weight(1f)
row {
text {
::content {
"Min: ${recyclerView!!.firstVisibleIndex.await()}, Max: ${recyclerView!!.lastVisibleIndex.await()}"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ object InfiniteImagesScreen : RockScreen {

object ReturnIndexList: List<Int>{
override val size: Int
get() = Int.MAX_VALUE
get() = 10_000
override fun get(index: Int): Int = index
override fun isEmpty(): Boolean = false
override fun iterator(): Iterator<Int> = (0..<Int.MAX_VALUE).iterator()
override fun iterator(): Iterator<Int> = (0..<10_000).iterator()
override fun listIterator(): ListIterator<Int> = object: ListIterator<Int> {
var n = -1
override fun hasNext(): Boolean = n < Int.MAX_VALUE
override fun hasNext(): Boolean = n < 10_000
override fun hasPrevious(): Boolean = n > 0
override fun next(): Int = ++n
override fun nextIndex(): Int = ++n
Expand All @@ -30,7 +30,7 @@ object InfiniteImagesScreen : RockScreen {
}
override fun listIterator(index: Int): ListIterator<Int> = object: ListIterator<Int> {
var n = index - 1
override fun hasNext(): Boolean = n < Int.MAX_VALUE
override fun hasNext(): Boolean = n < 10_000
override fun hasPrevious(): Boolean = n > 0
override fun next(): Int = ++n
override fun nextIndex(): Int = ++n
Expand All @@ -49,6 +49,7 @@ object InfiniteImagesScreen : RockScreen {
columns = 4
children(Constant(ReturnIndexList)) {
button {
spacing = 0.px
sizeConstraints(height = 16.rem) - image {
scaleType = ImageScaleType.Crop
::source { ImageRemote("https://picsum.photos/seed/${it.await()}/100/100") }
Expand All @@ -70,17 +71,20 @@ class ImageViewPager(val initialIndex: Int) : RockScreen {
stack {
viewPager {
children(Constant(InfiniteImagesScreen.ReturnIndexList)) { currImage ->
val renders = Property(0)
stack {
spacing = 0.25.rem
image {
reactiveScope {
renders.value++
val index = currImage.await()
source = ImageRemote("https://picsum.photos/seed/${index}/100/100")
delay(1)
source = ImageRemote("https://picsum.photos/seed/${index}/1000/1000")
}
scaleType = ImageScaleType.Fit
}
h2 { ::content { renders.await().toString() } }
}
}
index bind currentPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object RecyclerViewScreen : RockScreen {
recyclerView {
recyclerView = this
spacing = 0.5.rem
// columns = 2
columns = 2
this.scrollToIndex(10, Align.Start)
children(items) {
themeFromLast { theme ->
if(it.await() == 50) theme.important() else if(it.await() % 7 == 0) theme.hover() else theme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object RootScreen : RockScreen {
}
} in card

linkScreen(HorizontalRecyclerViewScreen)
linkScreen(InfiniteImagesScreen)
linkScreen(PlatformSpecificScreen)
linkScreen(VideoElementScreen)
Expand Down
2 changes: 1 addition & 1 deletion library/library.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'library'
spec.version = 'wasm-attempt-SNAPSHOT'
spec.version = 'main-SNAPSHOT'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ actual val Double.dp: Dimension

actual inline operator fun Dimension.plus(other: Dimension): Dimension = Dimension(this.value + other.value)
actual inline operator fun Dimension.minus(other: Dimension): Dimension = Dimension(this.value - other.value)
actual inline operator fun Dimension.times(other: Float): Dimension = Dimension(this.value * other.toInt())
actual inline operator fun Dimension.times(other: Float): Dimension = Dimension(this.value * other)
actual inline operator fun Dimension.div(other: Float): Dimension = Dimension(
if (other != 0f) {
val dimenValue = this.value / other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import com.lightningkite.rock.reactive.Property
import com.lightningkite.rock.views.direct.HasSpacingMultiplier
import com.lightningkite.rock.views.direct.RockLayoutTransition
import io.ktor.client.HttpClient
import io.ktor.client.plugins.cache.*
import io.ktor.client.plugins.cache.storage.*
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.http.*
import java.lang.RuntimeException
import java.lang.ref.WeakReference
import java.util.WeakHashMap
Expand All @@ -38,8 +41,13 @@ object AndroidAppContext {
val density: Float by lazy { res.displayMetrics.density }
val oneRem: Float by lazy { density * 14 }
var autoCompleteLayoutResource: Int = android.R.layout.simple_list_item_1
var ktorClient: HttpClient = HttpClient() {
install(WebSockets)
val ktorClient: HttpClient by lazy {
HttpClient() {
install(WebSockets)
install(HttpCache) {
publicStorage(FileStorage(applicationCtx.cacheDir.resolve("cachehttp")))
}
}
}
var activityCtxRef: WeakReference<RockActivity>? = null
var activityCtx: RockActivity?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ actual fun ViewWriter.weight(amount: Float): ViewWrapper {
lp.height = 0
}
} catch (ex: Throwable) {
throw RuntimeException("Weight is only available within a column or row, but the parent is a ${parent?.let { it::class.simpleName }}")
RuntimeException("Weight is only available within a column or row, but the parent is a ${parent?.let { it::class.simpleName }}").printStackTrace()
}
}
return ViewWrapper
Expand Down Expand Up @@ -138,6 +138,10 @@ class DesiredSizeView(context: Context) : ViewGroup(context) {
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
getChildAt(0).measure(
MeasureSpec.makeMeasureSpec(r-l, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(b-t, MeasureSpec.EXACTLY)
)
getChildAt(0).layout(0, 0, r - l, b - t)
}

Expand Down Expand Up @@ -265,17 +269,21 @@ actual fun ViewWriter.hasPopover(
preferredDirection: PopoverPreferredDirection,
setup: ViewWriter.(popoverContext: PopoverContext) -> Unit,
): ViewWrapper {
val originalNavigator = navigator
beforeNextElementSetup {
setOnClickListener {
navigator.dialog.navigate(object : RockScreen {
override fun ViewWriter.render() {
stack {
dismissBackground {
centered - stack {
setup(object: PopoverContext {
override fun close() {
navigator.dialog.dismiss()
}
})
with(split()) {
navigator = originalNavigator
setup(object : PopoverContext {
override fun close() {
navigator.dialog.dismiss()
}
})
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ inline fun <T : NView> ViewWriter.handleTheme(
val usePadding = (mightTransition && !isRoot || viewForcePadding || parentIsSwap)

if (usePadding) {
view.setPaddingAll(((view as? HasSpacingMultiplier)?.spacingOverride?.await() ?: theme.spacing).value.toInt().also {
if(parentIsSwap) println("Using padding of $it on a $view")
})
view.setPaddingAll(((view as? HasSpacingMultiplier)?.spacingOverride?.await() ?: theme.spacing).value.toInt())
} else {
view.setPaddingAll(0)
}

val parentSpacing = ((view.parent as? HasSpacingMultiplier)?.spacingOverride?.await() ?: theme.spacing).value
val parentSpacing = if(isRoot) 0f else ((view.parent as? HasSpacingMultiplier)?.spacingOverride?.await() ?: theme.spacing).value

if (viewLoads && view.androidCalculationContext.loading.await()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import android.widget.HorizontalScrollView
import android.widget.LinearLayout
import android.widget.ScrollView
import androidx.core.widget.NestedScrollView
import com.lightningkite.rock.views.direct.DesiredSizeView

val View.lparams: ViewGroup.LayoutParams get() {
if(layoutParams != null) return layoutParams
val parent = parent
if(parent is DesiredSizeView) return parent.lparams
if(layoutParams != null) return layoutParams
val newParams = when(parent) {
is LinearLayout -> LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
is FrameLayout -> FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
Expand Down
17 changes: 17 additions & 0 deletions library/src/iosMain/kotlin/com/lightningkite/rock/fetch.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.lightningkite.rock
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.cache.*
import io.ktor.client.plugins.cache.storage.*
import io.ktor.client.plugins.websocket.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand All @@ -19,6 +21,21 @@ import platform.posix.memcpy

val client = HttpClient {
install(WebSockets)
install(HttpCache) {
// publicStorage(object: CacheStorage {
// override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
// TODO("Not yet implemented")
// }
//
// override suspend fun findAll(url: Url): Set<CachedResponseData> {
// TODO("Not yet implemented")
// }
//
// override suspend fun store(url: Url, data: CachedResponseData) {
// TODO("Not yet implemented")
// }
// })
}
}

actual suspend fun fetch(
Expand Down
Loading

0 comments on commit b4bb98c

Please sign in to comment.