cashapp / redwood

Multiplatform reactive UI for Android, iOS, and web using Kotlin and Jetpack Compose
https://cashapp.github.io/redwood/0.x/docs/
Apache License 2.0
1.67k stars 73 forks source link

[jwilson] track when this view is detached from screen #293

Closed github-actions[bot] closed 2 years ago

github-actions[bot] commented 2 years ago

https://github.com/cashapp/redwood/blob/eb210ad552018dd4e9c53b655ad55425b07cc527/treehouse/src/nativeMain/kotlin/app/cash/treehouse/treehouseIos.kt#L33


/*
 * Copyright (C) 2022 Square, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.cash.treehouse

import kotlinx.cinterop.cValue
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import platform.CoreGraphics.CGRectZero
import platform.UIKit.UIStackView
import platform.UIKit.UIView

actual typealias View = UIView

actual class TreehouseView<T : Any>(
  private val content: TreehouseContent<T>,
) {
  val view = UIStackView(frame = cValue { CGRectZero })
  private var treehouseHost: TreehouseHost<T>? = null

  // TODO(jwilson): track when this view is detached from screen
  internal actual val boundContent: TreehouseContent<T>? = content

  fun register(treehouseHost: TreehouseHost<T>?) {
    this.treehouseHost = treehouseHost
    treehouseHost?.onContentChanged(this)
  }
}

// TODO(jwilson): we're currently doing everything on the main thread on iOS.
class IosTreehouseDispatchers : TreehouseDispatchers {
  override val main: CoroutineDispatcher = Dispatchers.Main
  override val zipline: CoroutineDispatcher = Dispatchers.Main

  override fun checkMain() {
  }

  override fun checkZipline() {
  }
}
github-actions[bot] commented 2 years ago

Closed in 7d10c6c84ca23955c1a424305001367e6cb3fb05

JakeWharton commented 2 years ago

Wow I've never seen one of these auto-close. 🎉