-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
465 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
example-app/src/commonMain/kotlin/com/lightningkite/mppexampleapp/ImageCropScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
library/src/androidMain/kotlin/com/lightningkite/rock/views/direct/ImageCrop.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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(): ImageRaw? { | ||
TODO("Not yet implemented") | ||
} | ||
} | ||
|
||
@ViewDsl | ||
actual fun ViewWriter.imageCropActual(setup: ImageCrop.() -> Unit) { | ||
TODO("Not yet implemented") | ||
} |
22 changes: 22 additions & 0 deletions
22
library/src/commonMain/kotlin/com/lightningkite/rock/views/direct/ImageCrop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.lightningkite.rock.views.direct | ||
|
||
import com.lightningkite.rock.models.ImageLocal | ||
import com.lightningkite.rock.models.ImageRaw | ||
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(): ImageRaw? | ||
} | ||
|
||
@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) } |
30 changes: 30 additions & 0 deletions
30
library/src/iosMain/kotlin/com/lightningkite/rock/views/direct/ImageCrop.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.lightningkite.rock.views.direct | ||
|
||
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(): ImageRaw? { | ||
TODO("Not yet implemented") | ||
} | ||
} | ||
|
||
@ViewDsl | ||
actual fun ViewWriter.imageCropActual(setup: ImageCrop.() -> Unit) { | ||
TODO("Not yet implemented") | ||
} |
Oops, something went wrong.