-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(android): lazy view renderer * fix: high initial page fails during lazy render * fix(android): programmatic scroll page index desync on heavy pages * chore(android): rename some functions
- Loading branch information
Showing
7 changed files
with
178 additions
and
66 deletions.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
android/src/main/java/com/reactnativepagerview/PagerDiffCallback.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,21 @@ | ||
package com.reactnativepagerview | ||
|
||
import androidx.recyclerview.widget.DiffUtil | ||
import com.reactnativepagerview.FragmentAdapter.Companion.UNRENDERED_ID_OFFSET | ||
|
||
class PagerDiffCallback(private val oldList: List<Long>, private val adapter: FragmentAdapter) : DiffUtil.Callback() { | ||
override fun getOldListSize() = oldList.size | ||
|
||
override fun getNewListSize() = adapter.itemCount | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
val oldId = oldList[oldItemPosition] | ||
val newId = adapter.getItemId(newItemPosition) | ||
// An unrendered item is assumed the same as any item in the same position. | ||
return if (oldId >= UNRENDERED_ID_OFFSET || newId >= UNRENDERED_ID_OFFSET) oldItemPosition == newItemPosition else oldId == newId | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition] == adapter.getItemId(newItemPosition) | ||
} | ||
} |
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
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
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
Oops, something went wrong.