Skip to content

Instantly share code, notes, and snippets.

View louis993546's full-sized avatar
😂

Louis Tsai louis993546

😂
View GitHub Profile
@louis993546
louis993546 / resources.md
Last active February 13, 2023 15:56
Resources for "Mental Models of Jetpack Compose"

Jetpack Compose and how did we end up here?

Index

  • The birth of modern smartphones
  • React is taking over the world
  • Reacting to React
  • How does Jetpack Compose fit into the picture

The birth of modern smartphone

@Composable
internal fun Text(/* params */) {
/* a lot of magic */
val children = @Composable {
Draw { canvas, _ ->
internalSelection.value?.let { renderParagraph.paintSelection(canvas, it) }
renderParagraph.paint(canvas, Offset(0.0f, 0.0f))
}
}
/* a lot more magic */
import androidx.compose.*
import androidx.ui.core.*
@Composable
fun Greeting(name: String) {
Text ("Hello $name!")
}
@louis993546
louis993546 / jetpackCompose.md
Last active April 10, 2022 18:34
Dive into Jetpack Compose and see what's inside

Diving into Jetpack Compose and see what's inside

Draft of what I will present

  • What Google said Jetpack Compose is
  • A really really quick recap of how Android draw stuff on screen right now
  • A quick look at the example code (i.e. how to use it)
  • Dig into how it actually works
    • What is it made of
  • Runtime
class PresenterWithDI(
private val networking: NetworkWrapper,
private val crashReporting: CrashReporting
) {
fun onSaveClicked() {
val (response, error) = networking.callTheApi()
if (error != null)
crashReporting.log("Oh no")
else
Log.d("DI", "Yay")
val currentLocation: Observable<LatLong> = TODO("the platform API keeps sending signal to this object")
currentLocation.subscribeBy(
onNext -> { latLong -> moveThePin(latLong) },
onError -> { throwable -> TODO("tell user that current location is not retrievable or something") },
onComplete -> { TODO("this is the end of the transmission, turn it off or something") })
fun moveThePin(latLong: LatLong) { TODO("move the Pin") }
interface ViewHolderFactory {
fun createViewHolder(parent: ViewGroup, onClick: () -> Unit): ViewHolder
}
class ViewHolderFactoryImpl1 : ViewHolderFactory {
override fun createViewHolder(parent: ViewGroup, onClick: () -> Unit): ViewHolder = TODO("")
}
class ViewHolderFactoryImpl2 : ViewHolderFactory {
override fun createViewHolder(parent: ViewGroup, onClick: () -> Unit): ViewHolder = TODO("")
@louis993546
louis993546 / Adapter.kt
Created May 14, 2019 23:03
Using Factory pattern for RecyclerView
class SomeAdapter(
val factory1: ViewHolderFactory1,
val factory2: ViewHOlderFactory2
): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun getItemViewType(position: Int) = if (position == 0) 1 else 2
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
1 -> factory1.createViewHolder(parent)
2 -> factory2.createViewHolder(parent)
else -> error("This should not be possible")
class SomethingActivity extends AppCompatActivity {
@Override
void onCreate() {
super.onCreate();
setContentView(R.layout.activity_something);
}
@Override
void onResume() {
retrofitService.someApiEndpoint().enqueue(this);