@shopify/flash-list 2.0.0-alpha.21 → 2.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnimatedFlashList.js +2 -2
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.d.ts +1 -167
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +3 -595
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +2 -63
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js.map +1 -1
- package/dist/__tests__/ViewabilityHelper.test.js +3 -4
- package/dist/__tests__/ViewabilityHelper.test.js.map +1 -1
- package/dist/benchmark/JSFPSMonitor.d.ts.map +1 -1
- package/dist/benchmark/JSFPSMonitor.js +2 -1
- package/dist/benchmark/JSFPSMonitor.js.map +1 -1
- package/dist/benchmark/useBenchmark.d.ts +2 -4
- package/dist/benchmark/useBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useBenchmark.js +12 -24
- package/dist/benchmark/useBenchmark.js.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +2 -1
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/errors/ErrorMessages.d.ts +16 -0
- package/dist/errors/ErrorMessages.d.ts.map +1 -0
- package/dist/errors/ErrorMessages.js +19 -0
- package/dist/errors/ErrorMessages.js.map +1 -0
- package/dist/errors/WarningMessages.d.ts +4 -0
- package/dist/errors/WarningMessages.d.ts.map +1 -0
- package/dist/errors/WarningMessages.js +7 -0
- package/dist/errors/WarningMessages.js.map +1 -0
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -29
- package/dist/index.js.map +1 -1
- package/dist/isNewArch.d.ts +2 -0
- package/dist/isNewArch.d.ts.map +1 -0
- package/dist/isNewArch.js +25 -0
- package/dist/isNewArch.js.map +1 -0
- package/dist/native/config/PlatformHelper.android.d.ts +1 -22
- package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +1 -16
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.d.ts +1 -22
- package/dist/native/config/PlatformHelper.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.d.ts +1 -22
- package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +1 -15
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +1 -16
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.d.ts +1 -23
- package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +1 -18
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +5 -0
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +9 -8
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RecyclerViewProps.d.ts +1 -8
- package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +4 -0
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +2 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/recyclerview/viewability/ViewToken.d.ts.map +1 -0
- package/dist/recyclerview/viewability/ViewToken.js.map +1 -0
- package/dist/{viewability → recyclerview/viewability}/ViewabilityHelper.d.ts +2 -2
- package/dist/recyclerview/viewability/ViewabilityHelper.d.ts.map +1 -0
- package/dist/{viewability → recyclerview/viewability}/ViewabilityHelper.js +2 -4
- package/dist/{viewability → recyclerview/viewability}/ViewabilityHelper.js.map +1 -1
- package/dist/{viewability → recyclerview/viewability}/ViewabilityManager.d.ts +3 -3
- package/dist/recyclerview/viewability/ViewabilityManager.d.ts.map +1 -0
- package/dist/{viewability → recyclerview/viewability}/ViewabilityManager.js +16 -16
- package/dist/recyclerview/viewability/ViewabilityManager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -14
- package/src/AnimatedFlashList.ts +2 -2
- package/src/FlashList.ts +1 -0
- package/src/FlashListProps.ts +3 -79
- package/src/__tests__/ViewabilityHelper.test.ts +13 -14
- package/src/benchmark/JSFPSMonitor.ts +3 -3
- package/src/benchmark/useBenchmark.ts +12 -40
- package/src/benchmark/useFlatListBenchmark.ts +3 -1
- package/src/errors/ErrorMessages.ts +26 -0
- package/src/errors/WarningMessages.ts +4 -0
- package/src/index.ts +7 -43
- package/src/isNewArch.ts +25 -0
- package/src/native/config/PlatformHelper.android.ts +1 -25
- package/src/native/config/PlatformHelper.ios.ts +1 -24
- package/src/native/config/PlatformHelper.ts +1 -25
- package/src/native/config/PlatformHelper.web.ts +1 -30
- package/src/recyclerview/RecyclerView.tsx +5 -0
- package/src/recyclerview/RecyclerViewManager.ts +9 -18
- package/src/recyclerview/RecyclerViewProps.ts +1 -11
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +4 -0
- package/src/recyclerview/layout-managers/LayoutManager.ts +2 -1
- package/src/{viewability → recyclerview/viewability}/ViewabilityHelper.ts +8 -9
- package/src/{viewability → recyclerview/viewability}/ViewabilityManager.ts +18 -20
- package/RNFlashList.podspec +0 -37
- package/android/build.gradle +0 -89
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutShadow.kt +0 -105
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutView.kt +0 -158
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutViewManager.kt +0 -70
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/BlankAreaEvent.kt +0 -29
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainer.java +0 -16
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerImpl.kt +0 -16
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerManager.kt +0 -34
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/FlashListPackage.kt +0 -19
- package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerDelegate.java +0 -47
- package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerInterface.java +0 -21
- package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerDelegate.java +0 -32
- package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerInterface.java +0 -16
- package/android/src/test/java/com/shopify/reactnative/flash_list/AutoLayoutShadowTest.kt +0 -147
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/Rect.kt +0 -61
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestCollection.kt +0 -6
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestDataModel.kt +0 -8
- package/android/src/test/resources/LayoutTestData.json +0 -788
- package/dist/GridLayoutProviderWithProps.d.ts +0 -42
- package/dist/GridLayoutProviderWithProps.d.ts.map +0 -1
- package/dist/GridLayoutProviderWithProps.js +0 -114
- package/dist/GridLayoutProviderWithProps.js.map +0 -1
- package/dist/MasonryFlashList.d.ts +0 -51
- package/dist/MasonryFlashList.d.ts.map +0 -1
- package/dist/MasonryFlashList.js +0 -252
- package/dist/MasonryFlashList.js.map +0 -1
- package/dist/PureComponentWrapper.d.ts +0 -22
- package/dist/PureComponentWrapper.d.ts.map +0 -1
- package/dist/PureComponentWrapper.js +0 -37
- package/dist/PureComponentWrapper.js.map +0 -1
- package/dist/__tests__/ContentContainerUtils.test.d.ts +0 -2
- package/dist/__tests__/ContentContainerUtils.test.d.ts.map +0 -1
- package/dist/__tests__/ContentContainerUtils.test.js +0 -85
- package/dist/__tests__/ContentContainerUtils.test.js.map +0 -1
- package/dist/__tests__/FlashList.test.d.ts +0 -2
- package/dist/__tests__/FlashList.test.d.ts.map +0 -1
- package/dist/__tests__/FlashList.test.js +0 -902
- package/dist/__tests__/FlashList.test.js.map +0 -1
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts +0 -2
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts.map +0 -1
- package/dist/__tests__/GridLayoutProviderWithProps.test.js +0 -143
- package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +0 -1
- package/dist/__tests__/MasonryFlashList.test.d.ts +0 -2
- package/dist/__tests__/MasonryFlashList.test.d.ts.map +0 -1
- package/dist/__tests__/MasonryFlashList.test.js +0 -254
- package/dist/__tests__/MasonryFlashList.test.js.map +0 -1
- package/dist/__tests__/PlatformHelper.web.test.d.ts +0 -2
- package/dist/__tests__/PlatformHelper.web.test.d.ts.map +0 -1
- package/dist/__tests__/PlatformHelper.web.test.js +0 -33
- package/dist/__tests__/PlatformHelper.web.test.js.map +0 -1
- package/dist/__tests__/helpers/mountFlashList.d.ts +0 -19
- package/dist/__tests__/helpers/mountFlashList.d.ts.map +0 -1
- package/dist/__tests__/helpers/mountFlashList.js +0 -44
- package/dist/__tests__/helpers/mountFlashList.js.map +0 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +0 -18
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +0 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.js +0 -49
- package/dist/__tests__/helpers/mountMasonryFlashList.js.map +0 -1
- package/dist/__tests__/useBlankAreaTracker.test.d.ts +0 -2
- package/dist/__tests__/useBlankAreaTracker.test.d.ts.map +0 -1
- package/dist/__tests__/useBlankAreaTracker.test.js +0 -179
- package/dist/__tests__/useBlankAreaTracker.test.js.map +0 -1
- package/dist/benchmark/useBlankAreaTracker.d.ts +0 -34
- package/dist/benchmark/useBlankAreaTracker.d.ts.map +0 -1
- package/dist/benchmark/useBlankAreaTracker.js +0 -66
- package/dist/benchmark/useBlankAreaTracker.js.map +0 -1
- package/dist/enableNewCore.d.ts +0 -3
- package/dist/enableNewCore.d.ts.map +0 -1
- package/dist/enableNewCore.js +0 -25
- package/dist/enableNewCore.js.map +0 -1
- package/dist/errors/CustomError.d.ts +0 -8
- package/dist/errors/CustomError.d.ts.map +0 -1
- package/dist/errors/CustomError.js +0 -14
- package/dist/errors/CustomError.js.map +0 -1
- package/dist/errors/ExceptionList.d.ts +0 -24
- package/dist/errors/ExceptionList.d.ts.map +0 -1
- package/dist/errors/ExceptionList.js +0 -26
- package/dist/errors/ExceptionList.js.map +0 -1
- package/dist/errors/Warnings.d.ts +0 -9
- package/dist/errors/Warnings.d.ts.map +0 -1
- package/dist/errors/Warnings.js +0 -13
- package/dist/errors/Warnings.js.map +0 -1
- package/dist/native/auto-layout/AutoLayoutView.d.ts +0 -22
- package/dist/native/auto-layout/AutoLayoutView.d.ts.map +0 -1
- package/dist/native/auto-layout/AutoLayoutView.js +0 -48
- package/dist/native/auto-layout/AutoLayoutView.js.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts +0 -4
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js +0 -6
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts +0 -5
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts +0 -4
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js +0 -6
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js +0 -6
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +0 -16
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +0 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js +0 -3
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js.map +0 -1
- package/dist/native/cell-container/CellContainer.android.d.ts +0 -6
- package/dist/native/cell-container/CellContainer.android.d.ts.map +0 -1
- package/dist/native/cell-container/CellContainer.android.js +0 -9
- package/dist/native/cell-container/CellContainer.android.js.map +0 -1
- package/dist/native/cell-container/CellContainer.d.ts +0 -8
- package/dist/native/cell-container/CellContainer.d.ts.map +0 -1
- package/dist/native/cell-container/CellContainer.ios.d.ts +0 -6
- package/dist/native/cell-container/CellContainer.ios.d.ts.map +0 -1
- package/dist/native/cell-container/CellContainer.ios.js +0 -9
- package/dist/native/cell-container/CellContainer.ios.js.map +0 -1
- package/dist/native/cell-container/CellContainer.js +0 -11
- package/dist/native/cell-container/CellContainer.js.map +0 -1
- package/dist/native/cell-container/CellContainer.web.d.ts +0 -7
- package/dist/native/cell-container/CellContainer.web.d.ts.map +0 -1
- package/dist/native/cell-container/CellContainer.web.js +0 -13
- package/dist/native/cell-container/CellContainer.web.js.map +0 -1
- package/dist/specs/AutoLayoutNativeComponent.d.ts +0 -18
- package/dist/specs/AutoLayoutNativeComponent.d.ts.map +0 -1
- package/dist/specs/AutoLayoutNativeComponent.js +0 -6
- package/dist/specs/AutoLayoutNativeComponent.js.map +0 -1
- package/dist/specs/CellContainerNativeComponent.d.ts +0 -8
- package/dist/specs/CellContainerNativeComponent.d.ts.map +0 -1
- package/dist/specs/CellContainerNativeComponent.js +0 -6
- package/dist/specs/CellContainerNativeComponent.js.map +0 -1
- package/dist/utils/ContentContainerUtils.d.ts +0 -27
- package/dist/utils/ContentContainerUtils.d.ts.map +0 -1
- package/dist/utils/ContentContainerUtils.js +0 -48
- package/dist/utils/ContentContainerUtils.js.map +0 -1
- package/dist/viewability/ViewToken.d.ts.map +0 -1
- package/dist/viewability/ViewToken.js.map +0 -1
- package/dist/viewability/ViewabilityHelper.d.ts.map +0 -1
- package/dist/viewability/ViewabilityManager.d.ts.map +0 -1
- package/dist/viewability/ViewabilityManager.js.map +0 -1
- package/ios/RNFlashList.xcodeproj/project.pbxproj +0 -3
- package/ios/RNFlashList.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/Sources/AutoLayoutView.swift +0 -294
- package/ios/Sources/AutoLayoutViewComponentView.h +0 -16
- package/ios/Sources/AutoLayoutViewComponentView.mm +0 -90
- package/ios/Sources/AutoLayoutViewManager.mm +0 -14
- package/ios/Sources/AutoLayoutViewManager.swift +0 -12
- package/ios/Sources/CellContainerComponentView.h +0 -18
- package/ios/Sources/CellContainerComponentView.mm +0 -62
- package/ios/Sources/CellContainerManager.mm +0 -8
- package/ios/Sources/CellContainerManager.swift +0 -12
- package/ios/Sources/FlatListPro-Bridging-Header.h +0 -11
- package/ios/Tests/AutoLayoutViewTests.swift +0 -113
- package/src/FlashList.tsx +0 -953
- package/src/GridLayoutProviderWithProps.ts +0 -180
- package/src/MasonryFlashList.tsx +0 -476
- package/src/PureComponentWrapper.tsx +0 -42
- package/src/__tests__/ContentContainerUtils.test.ts +0 -130
- package/src/__tests__/FlashList.test.tsx +0 -1001
- package/src/__tests__/GridLayoutProviderWithProps.test.ts +0 -179
- package/src/__tests__/MasonryFlashList.test.ts +0 -292
- package/src/__tests__/PlatformHelper.web.test.ts +0 -45
- package/src/__tests__/helpers/mountFlashList.tsx +0 -62
- package/src/__tests__/helpers/mountMasonryFlashList.tsx +0 -70
- package/src/__tests__/useBlankAreaTracker.test.tsx +0 -206
- package/src/benchmark/useBlankAreaTracker.ts +0 -117
- package/src/enableNewCore.ts +0 -24
- package/src/errors/CustomError.ts +0 -10
- package/src/errors/ExceptionList.ts +0 -28
- package/src/errors/Warnings.ts +0 -15
- package/src/native/auto-layout/AutoLayoutView.tsx +0 -73
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.android.ts +0 -7
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.ios.ts +0 -7
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.ts +0 -7
- package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +0 -17
- package/src/native/cell-container/CellContainer.android.ts +0 -7
- package/src/native/cell-container/CellContainer.ios.ts +0 -7
- package/src/native/cell-container/CellContainer.tsx +0 -14
- package/src/native/cell-container/CellContainer.web.tsx +0 -9
- package/src/specs/AutoLayoutNativeComponent.ts +0 -24
- package/src/specs/CellContainerNativeComponent.ts +0 -9
- package/src/utils/ContentContainerUtils.ts +0 -92
- /package/dist/{viewability → recyclerview/viewability}/ViewToken.d.ts +0 -0
- /package/dist/{viewability → recyclerview/viewability}/ViewToken.js +0 -0
- /package/src/{viewability → recyclerview/viewability}/ViewToken.ts +0 -0
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.graphics.Canvas
|
|
5
|
-
import android.util.DisplayMetrics
|
|
6
|
-
import android.util.Log
|
|
7
|
-
import android.view.View
|
|
8
|
-
import android.view.ViewGroup
|
|
9
|
-
import android.widget.HorizontalScrollView
|
|
10
|
-
import android.widget.ScrollView
|
|
11
|
-
import com.facebook.react.bridge.Arguments
|
|
12
|
-
import com.facebook.react.bridge.ReactContext
|
|
13
|
-
import com.facebook.react.bridge.WritableMap
|
|
14
|
-
import com.facebook.react.uimanager.UIManagerHelper
|
|
15
|
-
import com.facebook.react.uimanager.events.EventDispatcher
|
|
16
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
17
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** Container for all RecyclerListView children. This will automatically remove all gaps and overlaps for GridLayouts with flexible spans.
|
|
21
|
-
* Note: This cannot work for masonry layouts i.e, pinterest like layout */
|
|
22
|
-
class AutoLayoutView(context: Context) : ReactViewGroup(context) {
|
|
23
|
-
val alShadow = AutoLayoutShadow()
|
|
24
|
-
var enableInstrumentation = false
|
|
25
|
-
var disableAutoLayout = false
|
|
26
|
-
|
|
27
|
-
var pixelDensity = 1.0;
|
|
28
|
-
|
|
29
|
-
/** Overriding draw instead of onLayout. RecyclerListView uses absolute positions for each and every item which means that changes in child layouts may not trigger onLayout on this container. The same layout
|
|
30
|
-
* can still cause views to overlap. Therefore, it makes sense to override draw to do correction. */
|
|
31
|
-
override fun dispatchDraw(canvas: Canvas) {
|
|
32
|
-
fixLayout()
|
|
33
|
-
fixFooter()
|
|
34
|
-
super.dispatchDraw(canvas)
|
|
35
|
-
|
|
36
|
-
val parentScrollView = getParentScrollView()
|
|
37
|
-
if (enableInstrumentation && parentScrollView != null) {
|
|
38
|
-
/** Since we need to call this method with scrollOffset on the UI thread and not with the one react has we're querying parent's parent
|
|
39
|
-
directly which will be a ScrollView. If it isn't reported values will be incorrect but the component will not break.
|
|
40
|
-
RecyclerListView is expected not to change the hierarchy of children. */
|
|
41
|
-
|
|
42
|
-
val scrollContainerSize = if (alShadow.horizontal) parentScrollView.width else parentScrollView.height
|
|
43
|
-
|
|
44
|
-
val scrollOffset = if (alShadow.horizontal) parentScrollView.scrollX else parentScrollView.scrollY
|
|
45
|
-
|
|
46
|
-
val startOffset = if (alShadow.horizontal) left else top
|
|
47
|
-
val endOffset = if (alShadow.horizontal) right else bottom
|
|
48
|
-
|
|
49
|
-
val distanceFromWindowStart = kotlin.math.max(startOffset - scrollOffset, 0)
|
|
50
|
-
val distanceFromWindowEnd = kotlin.math.max(scrollOffset + scrollContainerSize - endOffset, 0)
|
|
51
|
-
|
|
52
|
-
alShadow.computeBlankFromGivenOffset(scrollOffset, distanceFromWindowStart, distanceFromWindowEnd)
|
|
53
|
-
emitBlankAreaEvent()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Sorts views by index and then invokes clearGaps which does the correction.
|
|
58
|
-
* Performance: Sort is needed. Given relatively low number of views in RecyclerListView render tree this should be a non issue.*/
|
|
59
|
-
private fun fixLayout() {
|
|
60
|
-
if (childCount > 1 && !disableAutoLayout) {
|
|
61
|
-
val positionSortedViews: Array<CellContainer> = Array(childCount) {
|
|
62
|
-
val child = getChildAt(it)
|
|
63
|
-
if (child is CellContainer) {
|
|
64
|
-
child
|
|
65
|
-
} else {
|
|
66
|
-
throw IllegalStateException("CellRendererComponent outer view should always be CellContainer. Learn more here: https://shopify.github.io/flash-list/docs/usage#cellrenderercomponent.")
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
positionSortedViews.sortBy { it.index }
|
|
70
|
-
alShadow.offsetFromStart = if (alShadow.horizontal) left else top
|
|
71
|
-
alShadow.clearGapsAndOverlaps(positionSortedViews)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Fixes footer position along with rest of the items */
|
|
76
|
-
private fun fixFooter() {
|
|
77
|
-
val parentScrollView = getParentScrollView()
|
|
78
|
-
if (disableAutoLayout || parentScrollView == null) {
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
val isAutoLayoutEndVisible = if (alShadow.horizontal) right <= parentScrollView.width else bottom <= parentScrollView.height
|
|
82
|
-
if (!isAutoLayoutEndVisible) {
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
val autoLayoutParent = parent as? View
|
|
86
|
-
val footer = getFooter();
|
|
87
|
-
val diff = getFooterDiff()
|
|
88
|
-
if (diff == 0 || footer == null || autoLayoutParent == null) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (alShadow.horizontal) {
|
|
93
|
-
footer.offsetLeftAndRight(diff)
|
|
94
|
-
right += diff
|
|
95
|
-
autoLayoutParent.right += diff
|
|
96
|
-
} else {
|
|
97
|
-
footer.offsetTopAndBottom(diff)
|
|
98
|
-
bottom += diff
|
|
99
|
-
autoLayoutParent.bottom += diff
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private fun getFooterDiff(): Int {
|
|
104
|
-
if (childCount == 0) {
|
|
105
|
-
alShadow.lastMaxBoundOverall = 0
|
|
106
|
-
} else if (childCount == 1) {
|
|
107
|
-
val firstChild = getChildAt(0)
|
|
108
|
-
alShadow.lastMaxBoundOverall = if (alShadow.horizontal) {
|
|
109
|
-
firstChild.right
|
|
110
|
-
} else {
|
|
111
|
-
firstChild.bottom
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
val autoLayoutEnd = if (alShadow.horizontal) right - left else bottom - top
|
|
115
|
-
return alShadow.lastMaxBoundOverall - autoLayoutEnd
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private fun getFooter(): View? {
|
|
119
|
-
return (parent as? ViewGroup)?.let {
|
|
120
|
-
for (i in 0 until it.childCount) {
|
|
121
|
-
val view = it.getChildAt(i)
|
|
122
|
-
if (view is CellContainer && view.index == -1) {
|
|
123
|
-
return@let view
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return@let null
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private fun getParentScrollView(): View? {
|
|
131
|
-
var autoLayoutParent = parent;
|
|
132
|
-
while (autoLayoutParent != null) {
|
|
133
|
-
if (autoLayoutParent is ScrollView || autoLayoutParent is HorizontalScrollView) {
|
|
134
|
-
return autoLayoutParent as View
|
|
135
|
-
}
|
|
136
|
-
autoLayoutParent = autoLayoutParent.parent;
|
|
137
|
-
}
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
private fun emitBlankAreaEvent() {
|
|
143
|
-
val eventDispatcher: EventDispatcher? =
|
|
144
|
-
UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
|
|
145
|
-
|
|
146
|
-
if (eventDispatcher != null) {
|
|
147
|
-
val surfaceId = UIManagerHelper.getSurfaceId(context as ReactContext)
|
|
148
|
-
eventDispatcher.dispatchEvent(
|
|
149
|
-
BlankAreaEvent(
|
|
150
|
-
surfaceId,
|
|
151
|
-
viewTag = id,
|
|
152
|
-
offsetStart = alShadow.blankOffsetAtStart / pixelDensity,
|
|
153
|
-
offsetEnd = alShadow.blankOffsetAtEnd / pixelDensity
|
|
154
|
-
)
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
-
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
|
-
import com.facebook.react.uimanager.ViewGroupManager
|
|
7
|
-
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
8
|
-
import com.facebook.react.viewmanagers.AutoLayoutViewManagerDelegate
|
|
9
|
-
import com.facebook.react.viewmanagers.AutoLayoutViewManagerInterface
|
|
10
|
-
import kotlin.math.roundToInt
|
|
11
|
-
|
|
12
|
-
/** ViewManager for AutoLayoutView - Container for all RecyclerListView children. Automatically removes all gaps and overlaps for GridLayouts with flexible spans.
|
|
13
|
-
* Note: This cannot work for masonry layouts i.e, pinterest like layout */
|
|
14
|
-
@ReactModule(name = AutoLayoutViewManager.REACT_CLASS)
|
|
15
|
-
class AutoLayoutViewManager: ViewGroupManager<AutoLayoutView>(), AutoLayoutViewManagerInterface<AutoLayoutView> {
|
|
16
|
-
private val mDelegate: AutoLayoutViewManagerDelegate<AutoLayoutView, AutoLayoutViewManager> =
|
|
17
|
-
AutoLayoutViewManagerDelegate(this)
|
|
18
|
-
|
|
19
|
-
companion object {
|
|
20
|
-
const val REACT_CLASS = "AutoLayoutView"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
override fun getName(): String {
|
|
24
|
-
return REACT_CLASS
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
override fun getDelegate(): ViewManagerDelegate<AutoLayoutView> = mDelegate
|
|
28
|
-
|
|
29
|
-
override fun createViewInstance(context: ThemedReactContext): AutoLayoutView {
|
|
30
|
-
return AutoLayoutView(context).also { it.pixelDensity = context.resources.displayMetrics.density.toDouble() }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
override fun getExportedCustomDirectEventTypeConstants() = mutableMapOf(
|
|
34
|
-
"onBlankAreaEvent" to mutableMapOf("registrationName" to "onBlankAreaEvent"),
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
@ReactProp(name = "horizontal")
|
|
38
|
-
override fun setHorizontal(view: AutoLayoutView, isHorizontal: Boolean) {
|
|
39
|
-
view.alShadow.horizontal = isHorizontal
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@ReactProp(name = "disableAutoLayout")
|
|
43
|
-
override fun setDisableAutoLayout(view: AutoLayoutView, disableAutoLayout: Boolean) {
|
|
44
|
-
view.disableAutoLayout = disableAutoLayout
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@ReactProp(name = "scrollOffset")
|
|
48
|
-
override fun setScrollOffset(view: AutoLayoutView, scrollOffset: Double) {
|
|
49
|
-
view.alShadow.scrollOffset = convertToPixelLayout(scrollOffset, view.pixelDensity)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@ReactProp(name = "windowSize")
|
|
53
|
-
override fun setWindowSize(view: AutoLayoutView, windowSize: Double) {
|
|
54
|
-
view.alShadow.windowSize = convertToPixelLayout(windowSize, view.pixelDensity)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@ReactProp(name = "renderAheadOffset")
|
|
58
|
-
override fun setRenderAheadOffset(view: AutoLayoutView, renderOffset: Double) {
|
|
59
|
-
view.alShadow.renderOffset = convertToPixelLayout(renderOffset, view.pixelDensity)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@ReactProp(name = "enableInstrumentation")
|
|
63
|
-
override fun setEnableInstrumentation(view: AutoLayoutView, enableInstrumentation: Boolean) {
|
|
64
|
-
view.enableInstrumentation = enableInstrumentation
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private fun convertToPixelLayout(dp: Double, density: Double): Int {
|
|
68
|
-
return (dp * density).roundToInt()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
@file:Suppress("DEPRECATION") // We want to use RCTEventEmitter for interop purposes
|
|
2
|
-
package com.shopify.reactnative.flash_list
|
|
3
|
-
|
|
4
|
-
import com.facebook.react.bridge.Arguments
|
|
5
|
-
import com.facebook.react.bridge.WritableMap
|
|
6
|
-
import com.facebook.react.uimanager.events.Event
|
|
7
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
8
|
-
|
|
9
|
-
class BlankAreaEvent(
|
|
10
|
-
surfaceId: Int,
|
|
11
|
-
viewTag: Int,
|
|
12
|
-
private val offsetStart: Double,
|
|
13
|
-
private val offsetEnd: Double
|
|
14
|
-
): Event<BlankAreaEvent>(surfaceId, viewTag) {
|
|
15
|
-
override fun getEventName() = EVENT_NAME
|
|
16
|
-
|
|
17
|
-
override fun getEventData(): WritableMap = Arguments.createMap().apply {
|
|
18
|
-
putDouble("offsetStart", offsetStart)
|
|
19
|
-
putDouble("offsetEnd", offsetEnd)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
|
|
23
|
-
rctEventEmitter.receiveEvent(viewTag, eventName, getEventData())
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
companion object {
|
|
27
|
-
const val EVENT_NAME: String = "onBlankAreaEvent"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list;
|
|
2
|
-
|
|
3
|
-
public interface CellContainer {
|
|
4
|
-
void setIndex(int value);
|
|
5
|
-
int getIndex();
|
|
6
|
-
void setLeft(int value);
|
|
7
|
-
int getLeft();
|
|
8
|
-
void setTop(int value);
|
|
9
|
-
int getTop();
|
|
10
|
-
void setRight(int value);
|
|
11
|
-
int getRight();
|
|
12
|
-
void setBottom(int value);
|
|
13
|
-
int getBottom();
|
|
14
|
-
int getHeight();
|
|
15
|
-
int getWidth();
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
5
|
-
|
|
6
|
-
class CellContainerImpl(context: Context) : ReactViewGroup(context), CellContainer {
|
|
7
|
-
private var index = -1
|
|
8
|
-
override fun setIndex(value: Int) {
|
|
9
|
-
index = value
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
override fun getIndex(): Int {
|
|
13
|
-
return index
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
-
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
|
-
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
7
|
-
import com.facebook.react.uimanager.annotations.ReactProp
|
|
8
|
-
import com.facebook.react.viewmanagers.CellContainerManagerDelegate
|
|
9
|
-
import com.facebook.react.viewmanagers.CellContainerManagerInterface
|
|
10
|
-
|
|
11
|
-
@ReactModule(name = AutoLayoutViewManager.REACT_CLASS)
|
|
12
|
-
class CellContainerManager: ViewGroupManager<CellContainerImpl>(), CellContainerManagerInterface<CellContainerImpl> {
|
|
13
|
-
private val mDelegate: CellContainerManagerDelegate<CellContainerImpl, CellContainerManager>
|
|
14
|
-
= CellContainerManagerDelegate(this)
|
|
15
|
-
|
|
16
|
-
companion object {
|
|
17
|
-
const val REACT_CLASS = "CellContainer"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
override fun getName(): String {
|
|
21
|
-
return REACT_CLASS
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
override fun getDelegate(): ViewManagerDelegate<CellContainerImpl> = mDelegate
|
|
25
|
-
|
|
26
|
-
override fun createViewInstance(context: ThemedReactContext): CellContainerImpl {
|
|
27
|
-
return CellContainerImpl(context)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@ReactProp(name = "index")
|
|
31
|
-
override fun setIndex(view: CellContainerImpl, index: Int) {
|
|
32
|
-
view.index = index
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.ReactPackage
|
|
4
|
-
import com.facebook.react.bridge.NativeModule
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.uimanager.ViewManager
|
|
7
|
-
|
|
8
|
-
class ReactNativeFlashListPackage : ReactPackage {
|
|
9
|
-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
|
-
return listOf()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
|
-
return listOf(
|
|
15
|
-
AutoLayoutViewManager(),
|
|
16
|
-
CellContainerManager()
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerDelegate.java
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GeneratePropsJavaDelegate.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
package com.facebook.react.viewmanagers;
|
|
11
|
-
|
|
12
|
-
import android.view.View;
|
|
13
|
-
import androidx.annotation.Nullable;
|
|
14
|
-
import com.facebook.react.uimanager.BaseViewManager;
|
|
15
|
-
import com.facebook.react.uimanager.BaseViewManagerDelegate;
|
|
16
|
-
import com.facebook.react.uimanager.LayoutShadowNode;
|
|
17
|
-
|
|
18
|
-
public class AutoLayoutViewManagerDelegate<T extends View, U extends BaseViewManager<T, ? extends LayoutShadowNode> & AutoLayoutViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
|
|
19
|
-
public AutoLayoutViewManagerDelegate(U viewManager) {
|
|
20
|
-
super(viewManager);
|
|
21
|
-
}
|
|
22
|
-
@Override
|
|
23
|
-
public void setProperty(T view, String propName, @Nullable Object value) {
|
|
24
|
-
switch (propName) {
|
|
25
|
-
case "horizontal":
|
|
26
|
-
mViewManager.setHorizontal(view, value == null ? false : (boolean) value);
|
|
27
|
-
break;
|
|
28
|
-
case "scrollOffset":
|
|
29
|
-
mViewManager.setScrollOffset(view, value == null ? 0f : ((Double) value).doubleValue());
|
|
30
|
-
break;
|
|
31
|
-
case "windowSize":
|
|
32
|
-
mViewManager.setWindowSize(view, value == null ? 0f : ((Double) value).doubleValue());
|
|
33
|
-
break;
|
|
34
|
-
case "renderAheadOffset":
|
|
35
|
-
mViewManager.setRenderAheadOffset(view, value == null ? 0f : ((Double) value).doubleValue());
|
|
36
|
-
break;
|
|
37
|
-
case "enableInstrumentation":
|
|
38
|
-
mViewManager.setEnableInstrumentation(view, value == null ? false : (boolean) value);
|
|
39
|
-
break;
|
|
40
|
-
case "disableAutoLayout":
|
|
41
|
-
mViewManager.setDisableAutoLayout(view, value == null ? false : (boolean) value);
|
|
42
|
-
break;
|
|
43
|
-
default:
|
|
44
|
-
super.setProperty(view, propName, value);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerInterface.java
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GeneratePropsJavaInterface.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
package com.facebook.react.viewmanagers;
|
|
11
|
-
|
|
12
|
-
import android.view.View;
|
|
13
|
-
|
|
14
|
-
public interface AutoLayoutViewManagerInterface<T extends View> {
|
|
15
|
-
void setHorizontal(T view, boolean value);
|
|
16
|
-
void setScrollOffset(T view, double value);
|
|
17
|
-
void setWindowSize(T view, double value);
|
|
18
|
-
void setRenderAheadOffset(T view, double value);
|
|
19
|
-
void setEnableInstrumentation(T view, boolean value);
|
|
20
|
-
void setDisableAutoLayout(T view, boolean value);
|
|
21
|
-
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerDelegate.java
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GeneratePropsJavaDelegate.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
package com.facebook.react.viewmanagers;
|
|
11
|
-
|
|
12
|
-
import android.view.View;
|
|
13
|
-
import androidx.annotation.Nullable;
|
|
14
|
-
import com.facebook.react.uimanager.BaseViewManager;
|
|
15
|
-
import com.facebook.react.uimanager.BaseViewManagerDelegate;
|
|
16
|
-
import com.facebook.react.uimanager.LayoutShadowNode;
|
|
17
|
-
|
|
18
|
-
public class CellContainerManagerDelegate<T extends View, U extends BaseViewManager<T, ? extends LayoutShadowNode> & CellContainerManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
|
|
19
|
-
public CellContainerManagerDelegate(U viewManager) {
|
|
20
|
-
super(viewManager);
|
|
21
|
-
}
|
|
22
|
-
@Override
|
|
23
|
-
public void setProperty(T view, String propName, @Nullable Object value) {
|
|
24
|
-
switch (propName) {
|
|
25
|
-
case "index":
|
|
26
|
-
mViewManager.setIndex(view, value == null ? 0 : ((Double) value).intValue());
|
|
27
|
-
break;
|
|
28
|
-
default:
|
|
29
|
-
super.setProperty(view, propName, value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerInterface.java
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
-
*
|
|
4
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
-
* once the code is regenerated.
|
|
6
|
-
*
|
|
7
|
-
* @generated by codegen project: GeneratePropsJavaInterface.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
package com.facebook.react.viewmanagers;
|
|
11
|
-
|
|
12
|
-
import android.view.View;
|
|
13
|
-
|
|
14
|
-
public interface CellContainerManagerInterface<T extends View> {
|
|
15
|
-
void setIndex(T view, int value);
|
|
16
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list
|
|
2
|
-
|
|
3
|
-
import com.google.gson.Gson
|
|
4
|
-
import com.shopify.reactnative.flash_list.models.Rect
|
|
5
|
-
import com.shopify.reactnative.flash_list.models.TestDataModel
|
|
6
|
-
import org.junit.Assert.assertEquals
|
|
7
|
-
import org.junit.Test
|
|
8
|
-
|
|
9
|
-
internal class AutoLayoutShadowTest {
|
|
10
|
-
private val gson = Gson()
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Test against expected output from stored JSON */
|
|
14
|
-
@Test
|
|
15
|
-
fun clearGapsAndOverlapsVerticalList() {
|
|
16
|
-
val alShadow = getAutolayoutShadow(0)
|
|
17
|
-
val testModel = getTestModel()
|
|
18
|
-
testModel.vertical.forEachIndexed { index, it ->
|
|
19
|
-
alShadow.clearGapsAndOverlaps(it.input as Array<CellContainer>)
|
|
20
|
-
assertEquals("Index: $index", gson.toJson(it.expectedOutput), gson.toJson(it.input))
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Test against expected output from stored JSON */
|
|
26
|
-
@Test
|
|
27
|
-
fun clearGapsAndOverlapsHorizontalList() {
|
|
28
|
-
val alShadow = getAutolayoutShadow(0)
|
|
29
|
-
alShadow.horizontal = true
|
|
30
|
-
val testModel = getTestModel()
|
|
31
|
-
testModel.horizontal.forEachIndexed { index, it ->
|
|
32
|
-
alShadow.clearGapsAndOverlaps(it.input as Array<CellContainer>)
|
|
33
|
-
assertEquals("Index: $index", gson.toJson(it.expectedOutput), gson.toJson(it.input))
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Test against expected output from stored JSON */
|
|
39
|
-
@Test
|
|
40
|
-
fun clearGapsAndOverlapsWindowSize() {
|
|
41
|
-
val alShadow = getAutolayoutShadow(0)
|
|
42
|
-
alShadow.horizontal = true
|
|
43
|
-
alShadow.windowSize = 90
|
|
44
|
-
val testModel = getTestModel()
|
|
45
|
-
testModel.window.forEachIndexed { index, it ->
|
|
46
|
-
alShadow.clearGapsAndOverlaps(it.input as Array<CellContainer>)
|
|
47
|
-
assertEquals("Index: $index", gson.toJson(it.expectedOutput), gson.toJson(it.input))
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Should only correct items in the visible window*/
|
|
53
|
-
@Test
|
|
54
|
-
fun clearGapsAndOverlapsBoundaryTest() {
|
|
55
|
-
val alShadow = getAutolayoutShadow(300)
|
|
56
|
-
alShadow.renderOffset = 100
|
|
57
|
-
|
|
58
|
-
//--------- Vertical -----------
|
|
59
|
-
//Item above visible window
|
|
60
|
-
arrayOf<CellContainer>(getRect(0, 0, 100, 100, 0), getRect(120, 0, 100, 100, 1)).let {
|
|
61
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
62
|
-
assertEquals(120, it[1].left)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//Item below visible window
|
|
66
|
-
arrayOf<CellContainer>(getRect(0, 0, 100, 100, 0), getRect(120, 850, 100, 950, 1)).let {
|
|
67
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
68
|
-
assertEquals(850, it[1].top)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//Item within visible window
|
|
72
|
-
arrayOf<CellContainer>(getRect(0, 250, 100, 100, 0), getRect(120, 250, 100, 100, 1)).let {
|
|
73
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
74
|
-
assertEquals(100, it[1].left)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//At the top edge
|
|
78
|
-
arrayOf<CellContainer>(getRect(0, 200, 100, 100, 0), getRect(120, 200, 100, 100, 1)).let {
|
|
79
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
80
|
-
assertEquals(100, it[1].left)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//--------- Horizontal -----------
|
|
84
|
-
|
|
85
|
-
alShadow.horizontal = true
|
|
86
|
-
|
|
87
|
-
//Item left of visible window
|
|
88
|
-
arrayOf<CellContainer>(getRect(0, 0, 100, 100, 0), getRect(0, 120, 100, 100, 1)).let {
|
|
89
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
90
|
-
assertEquals(120, it[1].top)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
//Item right of visible window
|
|
94
|
-
arrayOf<CellContainer>(getRect(0, 0, 100, 100, 0), getRect(850, 120, 950, 220, 1)).let {
|
|
95
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
96
|
-
assertEquals(120, it[1].top)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//Item within visible window
|
|
100
|
-
arrayOf<CellContainer>(getRect(250, 0, 100, 100, 0), getRect(250, 120, 100, 100, 1)).let {
|
|
101
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
102
|
-
assertEquals(100, it[1].top)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//At the left edge
|
|
106
|
-
arrayOf<CellContainer>(getRect(200, 0, 100, 100, 0), getRect(250, 150, 100, 100, 1)).let {
|
|
107
|
-
alShadow.clearGapsAndOverlaps(it)
|
|
108
|
-
assertEquals(100, it[1].top)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Test
|
|
113
|
-
fun checkBlankForLastItem() {
|
|
114
|
-
val alShadow = getAutolayoutShadow(0)
|
|
115
|
-
val testModel = getTestModel()
|
|
116
|
-
testModel.vertical.forEachIndexed { index, it ->
|
|
117
|
-
alShadow.clearGapsAndOverlaps(it.input as Array<CellContainer>)
|
|
118
|
-
it.expectedOutput.map { value -> value.bottom }.maxOrNull()?.let { max ->
|
|
119
|
-
alShadow.computeBlankFromGivenOffset(0, 0, 0)
|
|
120
|
-
assertEquals("Index: $index", alShadow.windowSize - max, alShadow.blankOffsetAtEnd)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private fun getTestModel(): TestDataModel {
|
|
126
|
-
var str = this.javaClass.classLoader.getResource("LayoutTestData.json").readText()
|
|
127
|
-
return gson.fromJson<TestDataModel>(str, TestDataModel::class.java)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private fun getRect(l: Int, t: Int, r: Int, b: Int, index: Int): Rect {
|
|
131
|
-
var rect = Rect(b - t, r - l)
|
|
132
|
-
rect.left = l
|
|
133
|
-
rect.right = r
|
|
134
|
-
rect.bottom = b
|
|
135
|
-
rect.top = t
|
|
136
|
-
rect.index = index
|
|
137
|
-
return rect
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private fun getAutolayoutShadow(offset: Int): AutoLayoutShadow {
|
|
141
|
-
val alShadow = AutoLayoutShadow()
|
|
142
|
-
alShadow.windowSize = 500
|
|
143
|
-
alShadow.renderOffset = 0
|
|
144
|
-
alShadow.scrollOffset = offset
|
|
145
|
-
return alShadow
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
package com.shopify.reactnative.flash_list.models
|
|
2
|
-
|
|
3
|
-
import com.shopify.reactnative.flash_list.CellContainer
|
|
4
|
-
|
|
5
|
-
class Rect (h: Int? = 0, w: Int? = 0): CellContainer {
|
|
6
|
-
private var left = 0
|
|
7
|
-
private var right = 0
|
|
8
|
-
private var top = 0
|
|
9
|
-
private var bottom = 0
|
|
10
|
-
private var height = 0
|
|
11
|
-
private var width = 0
|
|
12
|
-
private var index = 0
|
|
13
|
-
|
|
14
|
-
override fun setIndex(value: Int) {
|
|
15
|
-
index = value
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
override fun getIndex(): Int {
|
|
19
|
-
return index
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override fun setLeft(value: Int) {
|
|
23
|
-
left = value
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
override fun getLeft(): Int {
|
|
27
|
-
return left
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
override fun setTop(value: Int) {
|
|
31
|
-
top = value
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override fun getTop(): Int {
|
|
35
|
-
return top
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
override fun setRight(value: Int) {
|
|
39
|
-
right = value
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
override fun getRight(): Int {
|
|
43
|
-
return right
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override fun setBottom(value: Int) {
|
|
47
|
-
bottom = value
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override fun getBottom(): Int {
|
|
51
|
-
return bottom
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
override fun getHeight(): Int {
|
|
55
|
-
return height
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
override fun getWidth(): Int {
|
|
59
|
-
return width
|
|
60
|
-
}
|
|
61
|
-
}
|