Skip to content

Instantly share code, notes, and snippets.

@marenovakovic
marenovakovic / app.fs
Created January 24, 2023 12:23
F# Flutter app MyApp
type MyApp(?key: Key) =
inherit StatelessWidget(?key = key)
override _.build(context) =
MaterialApp(title = "Hello from F#!", home = ElmishWidget.From(init, update, view))
let main () = MyApp() |> runApp
@marenovakovic
marenovakovic / update.fs
Created January 24, 2023 12:21
F# Flutter app update
let update msg model =
match msg with
| Increment -> { model with count = model.count + 1 }, Cmd.none
| Decrement -> { model with count = model.count - 1 }, Cmd.none
@marenovakovic
marenovakovic / Main.fs
Created January 24, 2023 12:21
F# Flutter app view definition
let buttons dispatch : Widget =
Row(
mainAxisAlignment = MainAxisAlignment.center,
children =
[| MaterialButton(child = Text("Increment"), onPressed = fun () -> Increment |> dispatch)
MaterialButton(child = Text("Decrement"), onPressed = fun () -> Decrement |> dispatch)
SizedBox(width = 8) |]
)
let view model dispatch context : Widget =
@marenovakovic
marenovakovic / main.uikit.kt
Created January 4, 2023 11:44
Minimal Compose iOS app, Hello World
import androidx.compose.material.Text
import androidx.compose.ui.window.Application
import kotlinx.cinterop.ObjCObjectBase
import kotlinx.cinterop.autoreleasepool
import kotlinx.cinterop.cstr
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toCValues
import platform.Foundation.NSStringFromClass
import platform.UIKit.UIApplication
import platform.UIKit.UIApplicationDelegateProtocol
@marenovakovic
marenovakovic / settings.gradle.kts
Created January 4, 2023 11:38
Compose iOS Gradle settings
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
buildscript {
@marenovakovic
marenovakovic / build.gradle.kts
Last active February 6, 2023 08:00
Compose iOS gradle setup
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.compose.experimental.dsl.IOSDevices
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose") version "1.3.0-rc01"
}
version = "1.0"
data class Request(val endpoint: String)
data class Response(val body: String)
fun interface Processor : (Request) -> Response
val LoggingProcessor = { processor: Processor ->
Processor { request: Request -> processor(request).also(::println) }
}
private val cache = mutableMapOf<Request, Response>()
data class Topping(
val id: String,
val name: String,
)
data class Article(
val id: String,
val name: String,
val toppings: MutableList<Topping> = mutableListOf(),
) {
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap