Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions android/src/main/java/me/sectiontn/flume/FlumeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class FlumeAdapter(
var onPress: ((position: Int, pressId: String?, long: Boolean) -> Unit)? = null
var fullSpans = FullSpans(IntArray(0))
var onFirstData: (() -> Unit)? = null
// Every row binds again at the same data, which the list lays out without item animations.
var onRebindAll: (() -> Unit)? = null
var onDataChanged: ((reset: Boolean) -> Unit)? = null
var onStickyIndicesChanged: (() -> Unit)? = null
// Data indices of the applied data, from the store with each data change.
Expand All @@ -50,6 +52,7 @@ class FlumeAdapter(
}

private fun rebindAll() {
onRebindAll?.invoke()
measurer.invalidate()
if (storeId != 0) FlumeJni.invalidateMeasures(storeId)
// React grid cells take their width from JS, which learns it from the slot snapshot.
Expand Down
35 changes: 35 additions & 0 deletions android/src/main/java/me/sectiontn/flume/FlumeItemAnimator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package me.sectiontn.flume

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.RecyclerView

// RecyclerView's animator, held still for the layout that rebinds every row at a new shape or size.
class FlumeItemAnimator : DefaultItemAnimator() {
// Set before such a rebind and cleared once its layout completes, so its rows land in place instead of fading in.
var still = false

override fun animateAppearance(holder: RecyclerView.ViewHolder, pre: ItemHolderInfo?, post: ItemHolderInfo): Boolean =
if (still) settle(holder) else super.animateAppearance(holder, pre, post)

override fun animateDisappearance(holder: RecyclerView.ViewHolder, pre: ItemHolderInfo, post: ItemHolderInfo?): Boolean =
if (still) settle(holder) else super.animateDisappearance(holder, pre, post)

override fun animatePersistence(holder: RecyclerView.ViewHolder, pre: ItemHolderInfo, post: ItemHolderInfo): Boolean =
if (still) settle(holder) else super.animatePersistence(holder, pre, post)

override fun animateChange(
oldHolder: RecyclerView.ViewHolder,
newHolder: RecyclerView.ViewHolder,
pre: ItemHolderInfo,
post: ItemHolderInfo,
): Boolean {
if (!still) return super.animateChange(oldHolder, newHolder, pre, post)
if (newHolder !== oldHolder) dispatchAnimationFinished(newHolder)
return settle(oldHolder)
}

private fun settle(holder: RecyclerView.ViewHolder): Boolean {
dispatchAnimationFinished(holder)
return false
}
}
17 changes: 15 additions & 2 deletions android/src/main/java/me/sectiontn/flume/FlumeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.ViewConfiguration
import android.content.res.Configuration
import android.os.SystemClock
import android.widget.FrameLayout
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -94,7 +93,7 @@ class FlumeView(context: Context) : FrameLayout(context) {
}

// Change animations stay off so a rebind never flickers; false removes the animator entirely.
private val animator = DefaultItemAnimator().apply { supportsChangeAnimations = false }
private val animator = FlumeItemAnimator().apply { supportsChangeAnimations = false }
var itemAnimations = true
set(value) {
if (value == field) return
Expand Down Expand Up @@ -186,6 +185,7 @@ class FlumeView(context: Context) : FrameLayout(context) {

init {
slots.onRendered = { slot -> jumps.rendered(slot)?.let { runJump(it) } }
adapter.onRebindAll = { animator.still = true }
recycler.layoutManager = layoutManager
recycler.adapter = adapter
recycler.itemAnimator = animator
Expand Down Expand Up @@ -301,6 +301,7 @@ class FlumeView(context: Context) : FrameLayout(context) {
}

private fun onLaidOut() {
animator.still = false
if (reclaimOnLayout) {
reclaimOnLayout = false
slots.reclaim()
Expand Down Expand Up @@ -660,6 +661,18 @@ class FlumeView(context: Context) : FrameLayout(context) {
kept?.let { layoutManager.scrollToPositionWithOffset(it.firstVisiblePosition, it.firstVisibleOffsetPx) }
adapter.configure(horizontal, numColumns, inverted, paddingPx)
sticky.refresh(force = true)
layoutWithProps = true
}

// A new layout manager has no rows until it lays out, so it does in the frame of the props that made it.
private var layoutWithProps = false

fun afterProps() {
if (!layoutWithProps) return
layoutWithProps = false
if (width == 0 || height == 0) return
removeCallbacks(measureAndLayout)
measureAndLayout.run()
}

private fun applyDrawDistance() {
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/java/me/sectiontn/flume/FlumeViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class FlumeViewManager : ViewGroupManager<FlumeView>(), FlumeViewManagerInterfac

override fun createViewInstance(context: ThemedReactContext): FlumeView = FlumeView(context)

override fun onAfterUpdateTransaction(view: FlumeView) {
super.onAfterUpdateTransaction(view)
view.afterProps()
}

// Slot views live in holders and the bay; Fabric's child order is mirrored so its removeViewAt finds them.
override fun needsCustomLayoutForChildren(): Boolean = true

Expand Down
Loading