Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Mar 20, 2024
2 parents 61d0b70 + 733a6e9 commit 1f94c2b
Show file tree
Hide file tree
Showing 7 changed files with 488 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.lightningkite.mppexampleapp

import com.lightningkite.rock.ExternalServices
import com.lightningkite.rock.FileReference
import com.lightningkite.rock.Routable
import com.lightningkite.rock.models.ImageLocal
import com.lightningkite.rock.models.ImageRaw
import com.lightningkite.rock.models.rem
import com.lightningkite.rock.navigation.RockScreen
import com.lightningkite.rock.reactive.Property
import com.lightningkite.rock.reactive.await
import com.lightningkite.rock.reactive.awaitNotNull
import com.lightningkite.rock.views.*
import com.lightningkite.rock.views.direct.*

@Routable("image-crop")
object ImageCropScreen : RockScreen {
override fun ViewWriter.render() {
val image = Property<FileReference?>(null)
val croppedImage = Property<ImageRaw?>(null)
val imageCrop: ImageCrop

scrolls - col {
h1("Image Crop")
button {
text("Upload Image")
onClick {
ExternalServices.requestFile(listOf("image/*")) { uploaded ->
image.value = uploaded
}
}
}
centered - sizeConstraints(width = 20.rem, height = 20.rem) - imageCrop {
aspectRatio = 1 to 1
imageCrop = this
reactiveScope {
val imageSource = ImageLocal(image.awaitNotNull())
source = imageSource
}
}
button {
text("Crop")
onClick {
//croppedImage.value = imageCrop.crop()
}
}
centered - sizeConstraints(width = 20.rem, height = 20.rem) - image {
reactiveScope {
source = croppedImage.await()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ object RootScreen : RockScreen {
linkScreen(ReactivityScreen)
linkScreen(DialogSamplesScreen)
linkScreen(ExternalServicesScreen)
linkScreen(ImageCropScreen)
linkScreen(FullExampleScreen())
linkScreen(RecyclerViewScreen)
linkScreen(ArgumentsExampleScreen("test-id").also { it.toAdd.value = "Preset" })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.lightningkite.rock.views.direct

import android.view.View
import com.lightningkite.rock.Blob
import com.lightningkite.rock.models.ImageLocal
import com.lightningkite.rock.models.ImageRaw
import com.lightningkite.rock.views.RView
import com.lightningkite.rock.views.ViewDsl
import com.lightningkite.rock.views.ViewWriter

@Suppress("ACTUAL_WITHOUT_EXPECT")
actual typealias NImageCrop = View
actual class ImageCrop actual constructor(native: NImageCrop) : RView<NImageCrop> {
actual override val native: NImageCrop
get() = TODO("Not yet implemented")
actual var source: ImageLocal?
get() = TODO("Not yet implemented")
set(value) {}
actual var aspectRatio: Pair<Int, Int>?
get() = TODO("Not yet implemented")
set(value) {}

actual suspend fun crop(): Blob? {
TODO("Not yet implemented")
}
}

@ViewDsl
actual fun ViewWriter.imageCropActual(setup: ImageCrop.() -> Unit) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lightningkite.rock.views.direct

import com.lightningkite.rock.Blob
import com.lightningkite.rock.models.ImageLocal
import com.lightningkite.rock.views.NView
import com.lightningkite.rock.views.RView
import com.lightningkite.rock.views.ViewDsl
import com.lightningkite.rock.views.ViewWriter
import kotlin.contracts.*

expect class NImageCrop : NView

expect class ImageCrop(native: NImageCrop) : RView<NImageCrop> {
override val native: NImageCrop
var source: ImageLocal?
var aspectRatio: Pair<Int, Int>?
suspend fun crop(): Blob?
}

@ViewDsl
expect fun ViewWriter.imageCropActual(setup: ImageCrop.()->Unit = {}): Unit
@OptIn(ExperimentalContracts::class) @ViewDsl inline fun ViewWriter.imageCrop(noinline setup: ImageCrop.() -> Unit = {}) { contract { callsInPlace(setup, InvocationKind.EXACTLY_ONCE) }; imageCropActual(setup) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.lightningkite.rock.views.direct

import com.lightningkite.rock.Blob
import com.lightningkite.rock.models.ImageLocal
import com.lightningkite.rock.models.ImageRaw
import com.lightningkite.rock.views.RView
import com.lightningkite.rock.views.ViewDsl
import com.lightningkite.rock.views.ViewWriter
import platform.UIKit.UIView

@Suppress("ACTUAL_WITHOUT_EXPECT")
actual typealias NImageCrop = UIView
actual class ImageCrop actual constructor(native: NImageCrop) : RView<NImageCrop> {
actual override val native: NImageCrop
get() = TODO("Not yet implemented")
actual var source: ImageLocal?
get() = TODO("Not yet implemented")
set(value) {}
actual var aspectRatio: Pair<Int, Int>?
get() = TODO("Not yet implemented")
set(value) {}

actual suspend fun crop(): Blob? {
TODO("Not yet implemented")
}
}

@ViewDsl
actual fun ViewWriter.imageCropActual(setup: ImageCrop.() -> Unit) {
}
Loading

0 comments on commit 1f94c2b

Please sign in to comment.