react-native-list 1.0.1 → 2.0.0-alpha.2

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.
Files changed (224) hide show
  1. package/README.md +186 -32
  2. package/ReactNativeList.podspec +39 -0
  3. package/android/CMakeLists.txt +48 -0
  4. package/android/build.gradle +151 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/JHybridUiListModule.cpp +192 -0
  9. package/android/src/main/cpp/JHybridUiListModule.h +50 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +12 -0
  11. package/android/src/main/java/com/hannojg/reactnativelist/ReactNativeListPackage.kt +27 -0
  12. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListDataSource.kt +146 -0
  13. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListLayout.kt +86 -0
  14. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListModule.kt +116 -0
  15. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListView.kt +410 -0
  16. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridViewHolder.kt +9 -0
  17. package/android/src/main/java/com/margelo/nitro/reactnativelist/NativeListAdapter.kt +217 -0
  18. package/ios/DataSource/HybridNativeListDataSource.swift +213 -0
  19. package/ios/HybridObjects/HybridUiListModule.swift +49 -0
  20. package/ios/HybridObjects/HybridViewHolder.swift +16 -0
  21. package/ios/Layout/HybridNativeListLayout.swift +128 -0
  22. package/ios/Utils/ErrorUtils.h +26 -0
  23. package/ios/Utils/HybridIOSWorkletsModuleProxyHolder.swift +10 -0
  24. package/ios/Utils/SurfaceHelper.h +20 -0
  25. package/ios/Utils/SurfaceHelper.mm +144 -0
  26. package/ios/Utils/SurfacePresenterRegistry.h +17 -0
  27. package/ios/Utils/SurfacePresenterRegistry.m +31 -0
  28. package/ios/Utils/TurboModuleInstaller.h +18 -0
  29. package/ios/Utils/TurboModuleInstaller.mm +267 -0
  30. package/ios/Views/HostCell.swift +216 -0
  31. package/ios/Views/HybridUiListView.swift +695 -0
  32. package/lib/ReactFabricMirror.d.ts +4 -0
  33. package/lib/ReactFabricMirror.js +515 -0
  34. package/lib/UiListModule.d.ts +2 -0
  35. package/lib/UiListModule.js +2 -0
  36. package/lib/index.d.ts +8 -0
  37. package/lib/index.js +21 -0
  38. package/lib/privateGlobals.d.ts +14 -0
  39. package/lib/privateGlobals.js +2 -0
  40. package/lib/renderer/RenderHelper.d.ts +2 -0
  41. package/lib/renderer/RenderHelper.js +11 -0
  42. package/lib/renderer/UiManagerHelper.d.ts +2 -0
  43. package/lib/renderer/UiManagerHelper.js +2 -0
  44. package/lib/renderer/fabric/RenderHelper.d.ts +2 -0
  45. package/lib/renderer/fabric/RenderHelper.js +11 -0
  46. package/lib/renderer/fabric/UiManagerHelper.d.ts +2 -0
  47. package/lib/renderer/fabric/UiManagerHelper.js +2 -0
  48. package/lib/renderer/react/ReactFabricMirror.d.ts +4 -0
  49. package/lib/renderer/react/ReactFabricMirror.js +515 -0
  50. package/lib/renderer/react/ReactFabricRenderer.d.ts +3 -0
  51. package/lib/renderer/react/ReactFabricRenderer.js +9 -0
  52. package/lib/specs/IOSWorkletsModuleProxyHolder.nitro.d.ts +6 -0
  53. package/lib/specs/IOSWorkletsModuleProxyHolder.nitro.js +1 -0
  54. package/lib/specs/UIListModule.nitro.d.ts +9 -0
  55. package/lib/specs/UIListModule.nitro.js +1 -0
  56. package/lib/specs/UIManagerHelper.nitro.d.ts +13 -0
  57. package/lib/specs/UIManagerHelper.nitro.js +1 -0
  58. package/lib/specs/UiListView.nitro.d.ts +20 -0
  59. package/lib/specs/UiListView.nitro.js +1 -0
  60. package/lib/specs/ViewHolder.nitro.d.ts +6 -0
  61. package/lib/specs/ViewHolder.nitro.js +1 -0
  62. package/lib/views/List.d.ts +35 -0
  63. package/lib/views/List.js +225 -0
  64. package/lib/views/UiListHostComponent.d.ts +2 -0
  65. package/lib/views/UiListHostComponent.js +3 -0
  66. package/metro/RendererProxyThreadSwitch.js +66 -0
  67. package/metro-config.d.ts +1 -0
  68. package/metro-config.js +124 -0
  69. package/nitro.json +47 -0
  70. package/nitrogen/generated/.gitattributes +1 -0
  71. package/nitrogen/generated/android/ReactNativeList+autolinking.cmake +99 -0
  72. package/nitrogen/generated/android/ReactNativeList+autolinking.gradle +27 -0
  73. package/nitrogen/generated/android/ReactNativeListOnLoad.cpp +156 -0
  74. package/nitrogen/generated/android/ReactNativeListOnLoad.hpp +34 -0
  75. package/nitrogen/generated/android/c++/JFunc_bool_NativeListItem_NativeListItem.hpp +83 -0
  76. package/nitrogen/generated/android/c++/JFunc_bool_double_NativeListItem_double.hpp +83 -0
  77. package/nitrogen/generated/android/c++/JFunc_double_std__string.hpp +78 -0
  78. package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.cpp +49 -0
  79. package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.hpp +63 -0
  80. package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.cpp +63 -0
  81. package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.hpp +65 -0
  82. package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.cpp +101 -0
  83. package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.hpp +70 -0
  84. package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.cpp +49 -0
  85. package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.hpp +63 -0
  86. package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.cpp +65 -0
  87. package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.hpp +64 -0
  88. package/nitrogen/generated/android/c++/JHybridUiListViewSpec.cpp +92 -0
  89. package/nitrogen/generated/android/c++/JHybridUiListViewSpec.hpp +67 -0
  90. package/nitrogen/generated/android/c++/JHybridViewHolderSpec.cpp +49 -0
  91. package/nitrogen/generated/android/c++/JHybridViewHolderSpec.hpp +63 -0
  92. package/nitrogen/generated/android/c++/JNativeItemSizeEstimate.hpp +61 -0
  93. package/nitrogen/generated/android/c++/JNativeLinearListLayoutConfig.hpp +81 -0
  94. package/nitrogen/generated/android/c++/JNativeLinearListLayoutIOSConfig.hpp +59 -0
  95. package/nitrogen/generated/android/c++/JNativeListItem.hpp +76 -0
  96. package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.cpp +26 -0
  97. package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.hpp +72 -0
  98. package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.cpp +53 -0
  99. package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.hpp +49 -0
  100. package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.cpp +53 -0
  101. package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.hpp +49 -0
  102. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_NativeListItem_NativeListItem.kt +80 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_double_NativeListItem_double.kt +80 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_double_std__string.kt +80 -0
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridIOSWorkletsModuleProxyHolderSpec.kt +52 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeLinearListLayoutSpec.kt +54 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListDataSourceSpec.kt +87 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListLayoutSpec.kt +52 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListModuleSpec.kt +59 -0
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListViewSpec.kt +76 -0
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridViewHolderSpec.kt +53 -0
  112. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeItemSizeEstimate.kt +56 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutConfig.kt +76 -0
  114. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutIOSConfig.kt +51 -0
  115. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeListItem.kt +71 -0
  116. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/ReactNativeListOnLoad.kt +35 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Variant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.kt +62 -0
  118. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewManager.kt +80 -0
  119. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewStateUpdater.kt +23 -0
  120. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderManager.kt +80 -0
  121. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderStateUpdater.kt +23 -0
  122. package/nitrogen/generated/ios/ReactNativeList+autolinking.rb +62 -0
  123. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.cpp +162 -0
  124. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.hpp +368 -0
  125. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Umbrella.hpp +92 -0
  126. package/nitrogen/generated/ios/ReactNativeListAutolinking.mm +83 -0
  127. package/nitrogen/generated/ios/ReactNativeListAutolinking.swift +86 -0
  128. package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.cpp +11 -0
  129. package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.hpp +75 -0
  130. package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.cpp +11 -0
  131. package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.hpp +92 -0
  132. package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.cpp +11 -0
  133. package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.hpp +132 -0
  134. package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.cpp +11 -0
  135. package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.hpp +75 -0
  136. package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.cpp +11 -0
  137. package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.hpp +93 -0
  138. package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.cpp +11 -0
  139. package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.hpp +121 -0
  140. package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.cpp +11 -0
  141. package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.hpp +75 -0
  142. package/nitrogen/generated/ios/c++/views/HybridUiListViewComponent.mm +118 -0
  143. package/nitrogen/generated/ios/c++/views/HybridViewHolderComponent.mm +118 -0
  144. package/nitrogen/generated/ios/swift/Func_bool_NativeListItem_NativeListItem.swift +47 -0
  145. package/nitrogen/generated/ios/swift/Func_bool_double_NativeListItem_double.swift +47 -0
  146. package/nitrogen/generated/ios/swift/Func_double_std__string.swift +47 -0
  147. package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec.swift +55 -0
  148. package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec_cxx.swift +128 -0
  149. package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec.swift +55 -0
  150. package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec_cxx.swift +140 -0
  151. package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec.swift +62 -0
  152. package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec_cxx.swift +222 -0
  153. package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec.swift +55 -0
  154. package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec_cxx.swift +128 -0
  155. package/nitrogen/generated/ios/swift/HybridUiListModuleSpec.swift +56 -0
  156. package/nitrogen/generated/ios/swift/HybridUiListModuleSpec_cxx.swift +175 -0
  157. package/nitrogen/generated/ios/swift/HybridUiListViewSpec.swift +59 -0
  158. package/nitrogen/generated/ios/swift/HybridUiListViewSpec_cxx.swift +227 -0
  159. package/nitrogen/generated/ios/swift/HybridViewHolderSpec.swift +55 -0
  160. package/nitrogen/generated/ios/swift/HybridViewHolderSpec_cxx.swift +147 -0
  161. package/nitrogen/generated/ios/swift/NativeItemSizeEstimate.swift +60 -0
  162. package/nitrogen/generated/ios/swift/NativeLinearListLayoutConfig.swift +60 -0
  163. package/nitrogen/generated/ios/swift/NativeLinearListLayoutIOSConfig.swift +35 -0
  164. package/nitrogen/generated/ios/swift/NativeListItem.swift +75 -0
  165. package/nitrogen/generated/ios/swift/Variant_NullType__any_HybridIOSWorkletsModuleProxyHolderSpec_.swift +30 -0
  166. package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.cpp +21 -0
  167. package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.hpp +62 -0
  168. package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.cpp +22 -0
  169. package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.hpp +67 -0
  170. package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.cpp +28 -0
  171. package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.hpp +72 -0
  172. package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.cpp +21 -0
  173. package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.hpp +62 -0
  174. package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.cpp +22 -0
  175. package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.hpp +68 -0
  176. package/nitrogen/generated/shared/c++/HybridUiListViewSpec.cpp +25 -0
  177. package/nitrogen/generated/shared/c++/HybridUiListViewSpec.hpp +79 -0
  178. package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.cpp +23 -0
  179. package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.hpp +65 -0
  180. package/nitrogen/generated/shared/c++/HybridViewHolderSpec.cpp +21 -0
  181. package/nitrogen/generated/shared/c++/HybridViewHolderSpec.hpp +62 -0
  182. package/nitrogen/generated/shared/c++/NativeItemSizeEstimate.hpp +87 -0
  183. package/nitrogen/generated/shared/c++/NativeLinearListLayoutConfig.hpp +105 -0
  184. package/nitrogen/generated/shared/c++/NativeLinearListLayoutIOSConfig.hpp +85 -0
  185. package/nitrogen/generated/shared/c++/NativeListItem.hpp +101 -0
  186. package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.cpp +72 -0
  187. package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.hpp +109 -0
  188. package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.cpp +72 -0
  189. package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.hpp +109 -0
  190. package/nitrogen/generated/shared/json/UiListViewConfig.json +9 -0
  191. package/nitrogen/generated/shared/json/ViewHolderConfig.json +9 -0
  192. package/package.json +152 -5
  193. package/react-native.config.js +16 -0
  194. package/src/ListDataSource.ts +232 -0
  195. package/src/ListLayout.ts +95 -0
  196. package/src/UiListModule.ts +5 -0
  197. package/src/hooks/useChangeEffect.ts +50 -0
  198. package/src/index.tsx +49 -0
  199. package/src/privateGlobals.ts +20 -0
  200. package/src/renderer/fabric/RenderHelper.ts +29 -0
  201. package/src/renderer/fabric/UiManagerHelper.ts +5 -0
  202. package/src/renderer/react/ReactFabricMirror.bundle.js +1984 -0
  203. package/src/renderer/react/ReactFabricMirror.ts +766 -0
  204. package/src/renderer/react/ReactFabricRenderer.ts +11 -0
  205. package/src/specs/IOSWorkletsModuleProxyHolder.nitro.ts +6 -0
  206. package/src/specs/NativeLinearListLayout.nitro.ts +23 -0
  207. package/src/specs/NativeListDataSource.nitro.ts +28 -0
  208. package/src/specs/NativeListLayout.nitro.ts +6 -0
  209. package/src/specs/UIListModule.nitro.ts +13 -0
  210. package/src/specs/UIManagerHelper.nitro.ts +34 -0
  211. package/src/specs/UiListView.nitro.ts +31 -0
  212. package/src/specs/ViewHolder.nitro.ts +11 -0
  213. package/src/views/List.tsx +525 -0
  214. package/src/views/UiListHostComponent.ts +8 -0
  215. package/FillRateHelper.js +0 -179
  216. package/FlatList.js +0 -494
  217. package/LICENSE.md +0 -31
  218. package/MetroListView.js +0 -166
  219. package/SectionList.js +0 -291
  220. package/ViewabilityHelper.js +0 -260
  221. package/VirtualizeUtils.js +0 -163
  222. package/VirtualizedList.js +0 -861
  223. package/VirtualizedSectionList.js +0 -397
  224. package/index.js +0 -5
package/LICENSE.md DELETED
@@ -1,31 +0,0 @@
1
- BSD License
2
-
3
- For React Native software
4
-
5
- Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
6
- Copyright (c) 2017-present, Alexey Kureev
7
-
8
- Redistribution and use in source and binary forms, with or without modification,
9
- are permitted provided that the following conditions are met:
10
-
11
- * Redistributions of source code must retain the above copyright notice, this
12
- list of conditions and the following disclaimer.
13
-
14
- * Redistributions in binary form must reproduce the above copyright notice,
15
- this list of conditions and the following disclaimer in the documentation
16
- and/or other materials provided with the distribution.
17
-
18
- * Neither the name Facebook nor the names of its contributors may be used to
19
- endorse or promote products derived from this software without specific
20
- prior written permission.
21
-
22
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/MetroListView.js DELETED
@@ -1,166 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule MetroListView
10
- * @flow
11
- */
12
- 'use strict';
13
-
14
- const ListView = require('ListView');
15
- const React = require('React');
16
- const RefreshControl = require('RefreshControl');
17
- const ScrollView = require('ScrollView');
18
-
19
- const invariant = require('fbjs/lib/invariant');
20
-
21
- type Item = any;
22
-
23
- type NormalProps = {
24
- FooterComponent?: ReactClass<*>,
25
- renderItem: (info: Object) => ?React.Element<*>,
26
- renderSectionHeader?: ({section: Object}) => ?React.Element<*>,
27
- SeparatorComponent?: ?ReactClass<*>, // not supported yet
28
-
29
- // Provide either `items` or `sections`
30
- items?: ?Array<Item>, // By default, an Item is assumed to be {key: string}
31
- // $FlowFixMe - Something is a little off with the type Array<Item>
32
- sections?: ?Array<{key: string, data: Array<Item>}>,
33
-
34
- /**
35
- * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
36
- * sure to also set the `refreshing` prop correctly.
37
- */
38
- onRefresh?: ?Function,
39
- /**
40
- * Set this true while waiting for new data from a refresh.
41
- */
42
- refreshing?: boolean,
43
- /**
44
- * If true, renders items next to each other horizontally instead of stacked vertically.
45
- */
46
- horizontal?: ?boolean,
47
- };
48
- type DefaultProps = {
49
- keyExtractor: (item: Item, index: number) => string,
50
- };
51
- /* $FlowFixMe - the renderItem passed in from SectionList is optional there but
52
- * required here */
53
- type Props = NormalProps & DefaultProps;
54
-
55
- /**
56
- * This is just a wrapper around the legacy ListView that matches the new API of FlatList, but with
57
- * some section support tacked on. It is recommended to just use FlatList directly, this component
58
- * is mostly for debugging and performance comparison.
59
- */
60
- class MetroListView extends React.Component {
61
- props: Props;
62
- scrollToEnd(params?: ?{animated?: ?boolean}) {
63
- throw new Error('scrollToEnd not supported in legacy ListView.');
64
- }
65
- scrollToIndex(params: {animated?: ?boolean, index: number, viewPosition?: number}) {
66
- throw new Error('scrollToIndex not supported in legacy ListView.');
67
- }
68
- scrollToItem(params: {animated?: ?boolean, item: Item, viewPosition?: number}) {
69
- throw new Error('scrollToItem not supported in legacy ListView.');
70
- }
71
- scrollToLocation() {
72
- throw new Error('scrollToLocation not supported in legacy ListView.');
73
- }
74
- scrollToOffset(params: {animated?: ?boolean, offset: number}) {
75
- const {animated, offset} = params;
76
- this._listRef.scrollTo(
77
- this.props.horizontal ? {x: offset, animated} : {y: offset, animated}
78
- );
79
- }
80
- getListRef() {
81
- return this._listRef;
82
- }
83
- static defaultProps: DefaultProps = {
84
- keyExtractor: (item, index) => item.key || String(index),
85
- renderScrollComponent: (props: Props) => {
86
- if (props.onRefresh) {
87
- return (
88
- <ScrollView
89
- {...props}
90
- refreshControl={
91
- <RefreshControl
92
- refreshing={props.refreshing}
93
- onRefresh={props.onRefresh}
94
- />
95
- }
96
- />
97
- );
98
- } else {
99
- return <ScrollView {...props} />;
100
- }
101
- },
102
- };
103
- state = this._computeState(
104
- this.props,
105
- {
106
- ds: new ListView.DataSource({
107
- rowHasChanged: (itemA, itemB) => true,
108
- sectionHeaderHasChanged: () => true,
109
- getSectionHeaderData: (dataBlob, sectionID) => this.state.sectionHeaderData[sectionID],
110
- }),
111
- sectionHeaderData: {},
112
- },
113
- );
114
- componentWillReceiveProps(newProps: Props) {
115
- this.setState((state) => this._computeState(newProps, state));
116
- }
117
- render() {
118
- return (
119
- <ListView
120
- {...this.props}
121
- dataSource={this.state.ds}
122
- ref={this._captureRef}
123
- renderRow={this._renderRow}
124
- renderFooter={this.props.FooterComponent && this._renderFooter}
125
- renderSectionHeader={this.props.sections && this._renderSectionHeader}
126
- renderSeparator={this.props.SeparatorComponent && this._renderSeparator}
127
- />
128
- );
129
- }
130
- _listRef: ListView;
131
- _captureRef = (ref) => { this._listRef = ref; };
132
- _computeState(props: Props, state) {
133
- const sectionHeaderData = {};
134
- if (props.sections) {
135
- invariant(!props.items, 'Cannot have both sections and items props.');
136
- const sections = {};
137
- props.sections.forEach((sectionIn, ii) => {
138
- const sectionID = 's' + ii;
139
- sections[sectionID] = sectionIn.data;
140
- sectionHeaderData[sectionID] = sectionIn;
141
- });
142
- return {
143
- ds: state.ds.cloneWithRowsAndSections(sections),
144
- sectionHeaderData,
145
- };
146
- } else {
147
- invariant(!props.sections, 'Cannot have both sections and items props.');
148
- return {
149
- ds: state.ds.cloneWithRows(props.items),
150
- sectionHeaderData,
151
- };
152
- }
153
- }
154
- _renderFooter = () => <this.props.FooterComponent key="$footer" />;
155
- _renderRow = (item, sectionID, rowID, highlightRow) => {
156
- return this.props.renderItem({item, index: rowID});
157
- };
158
- _renderSectionHeader = (section, sectionID) => {
159
- const {renderSectionHeader} = this.props;
160
- invariant(renderSectionHeader, 'Must provide renderSectionHeader with sections prop');
161
- return renderSectionHeader({section});
162
- }
163
- _renderSeparator = (sID, rID) => <this.props.SeparatorComponent key={sID + rID} />;
164
- }
165
-
166
- module.exports = MetroListView;
package/SectionList.js DELETED
@@ -1,291 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule SectionList
10
- * @flow
11
- */
12
- 'use strict';
13
-
14
- const MetroListView = require('MetroListView');
15
- const Platform = require('Platform');
16
- const React = require('React');
17
- const VirtualizedSectionList = require('VirtualizedSectionList');
18
-
19
- import type {ViewToken} from 'ViewabilityHelper';
20
- import type {Props as VirtualizedSectionListProps} from 'VirtualizedSectionList';
21
-
22
- type Item = any;
23
-
24
- type SectionBase<SectionItemT> = {
25
- // Must be provided directly on each section.
26
- data: Array<SectionItemT>,
27
- key: string,
28
-
29
- // Optional props will override list-wide props just for this section.
30
- renderItem?: ?(info: {
31
- item: SectionItemT,
32
- index: number,
33
- separators: {
34
- highlight: () => void,
35
- unhighlight: () => void,
36
- updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
37
- },
38
- }) => ?React.Element<any>,
39
- ItemSeparatorComponent?: ?ReactClass<any>,
40
- keyExtractor?: (item: SectionItemT) => string,
41
-
42
- // TODO: support more optional/override props
43
- // onViewableItemsChanged?: ...
44
- };
45
-
46
- type RequiredProps<SectionT: SectionBase<any>> = {
47
- /**
48
- * The actual data to render, akin to the `data` prop in [`<FlatList>`](/react-native/docs/flatlist.html).
49
- *
50
- * General shape:
51
- *
52
- * sections: Array<{
53
- * data: Array<SectionItem>,
54
- * key: string,
55
- * renderItem?: ({item: SectionItem, ...}) => ?React.Element<*>,
56
- * ItemSeparatorComponent?: ?ReactClass<{highlighted: boolean, ...}>,
57
- * }>
58
- */
59
- sections: Array<SectionT>,
60
- };
61
-
62
- type OptionalProps<SectionT: SectionBase<any>> = {
63
- /**
64
- * Default renderer for every item in every section. Can be over-ridden on a per-section basis.
65
- */
66
- renderItem: (info: {
67
- item: Item,
68
- index: number,
69
- separators: {
70
- highlight: () => void,
71
- unhighlight: () => void,
72
- updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
73
- },
74
- }) => ?React.Element<any>,
75
- /**
76
- * Rendered in between each item, but not at the top or bottom. By default, `highlighted` and
77
- * `leadingItem` props are provided. `renderItem` provides `separators.highlight`/`unhighlight`
78
- * which will update the `highlighted` prop, but you can also add custom props with
79
- * `separators.updateProps`.
80
- */
81
- ItemSeparatorComponent?: ?ReactClass<any>,
82
- /**
83
- * Rendered at the very beginning of the list.
84
- */
85
- ListHeaderComponent?: ?(ReactClass<any> | React.Element<any>),
86
- /**
87
- * Rendered at the very end of the list.
88
- */
89
- ListFooterComponent?: ?(ReactClass<any> | React.Element<any>),
90
- /**
91
- * Rendered in between each section. Also receives `highlighted`, `leadingItem`, and any custom
92
- * props from `separators.updateProps`.
93
- */
94
- SectionSeparatorComponent?: ?ReactClass<any>,
95
- /**
96
- * A marker property for telling the list to re-render (since it implements `PureComponent`). If
97
- * any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
98
- * `data` prop, stick it here and treat it immutably.
99
- */
100
- extraData?: any,
101
- /**
102
- * How many items to render in the initial batch. This should be enough to fill the screen but not
103
- * much more. Note these items will never be unmounted as part of the windowed rendering in order
104
- * to improve perceived performance of scroll-to-top actions.
105
- */
106
- initialNumToRender: number,
107
- /**
108
- * Used to extract a unique key for a given item at the specified index. Key is used for caching
109
- * and as the react key to track item re-ordering. The default extractor checks item.key, then
110
- * falls back to using the index, like react does.
111
- */
112
-
113
- keyExtractor: (item: Item, index: number) => string,
114
- /**
115
- * Called once when the scroll position gets within `onEndReachedThreshold` of the rendered
116
- * content.
117
- */
118
- onEndReached?: ?(info: {distanceFromEnd: number}) => void,
119
- /**
120
- * How far from the end (in units of visible length of the list) the bottom edge of the
121
- * list must be from the end of the content to trigger the `onEndReached` callback.
122
- * Thus a value of 0.5 will trigger `onEndReached` when the end of the content is
123
- * within half the visible length of the list.
124
- */
125
- onEndReachedThreshold?: ?number,
126
- /**
127
- * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
128
- * sure to also set the `refreshing` prop correctly.
129
- */
130
- onRefresh?: ?() => void,
131
- /**
132
- * Called when the viewability of rows changes, as defined by the
133
- * `viewabilityConfig` prop.
134
- */
135
- onViewableItemsChanged?: ?(info: {
136
- viewableItems: Array<ViewToken>,
137
- changed: Array<ViewToken>,
138
- }) => void,
139
- /**
140
- * Set this true while waiting for new data from a refresh.
141
- */
142
- refreshing?: ?boolean,
143
- /**
144
- * Note: may have bugs (missing content) in some circumstances - use at your own risk.
145
- *
146
- * This may improve scroll performance for large lists.
147
- */
148
- removeClippedSubviews?: boolean,
149
- /**
150
- * Rendered at the top of each section. These stick to the top of the `ScrollView` by default on
151
- * iOS. See `stickySectionHeadersEnabled`.
152
- */
153
- renderSectionHeader?: ?(info: {section: SectionT}) => ?React.Element<any>,
154
- /**
155
- * Makes section headers stick to the top of the screen until the next one pushes it off. Only
156
- * enabled by default on iOS because that is the platform standard there.
157
- */
158
- stickySectionHeadersEnabled?: boolean,
159
-
160
- legacyImplementation?: ?boolean,
161
- };
162
-
163
- type Props<SectionT> = RequiredProps<SectionT>
164
- & OptionalProps<SectionT>
165
- & VirtualizedSectionListProps<SectionT>;
166
-
167
- const defaultProps = {
168
- ...VirtualizedSectionList.defaultProps,
169
- stickySectionHeadersEnabled: Platform.OS === 'ios',
170
- };
171
-
172
- type DefaultProps = typeof defaultProps;
173
-
174
- /**
175
- * A performant interface for rendering sectioned lists, supporting the most handy features:
176
- *
177
- * - Fully cross-platform.
178
- * - Configurable viewability callbacks.
179
- * - List header support.
180
- * - List footer support.
181
- * - Item separator support.
182
- * - Section header support.
183
- * - Section separator support.
184
- * - Heterogeneous data and item rendering support.
185
- * - Pull to Refresh.
186
- * - Scroll loading.
187
- *
188
- * If you don't need section support and want a simpler interface, use
189
- * [`<FlatList>`](/react-native/docs/flatlist.html).
190
- *
191
- * Simple Examples:
192
- *
193
- * <SectionList
194
- * renderItem={({item}) => <ListItem title={item.title}}
195
- * renderSectionHeader={({section}) => <H1 title={section.key} />}
196
- * sections={[ // homogenous rendering between sections
197
- * {data: [...], key: ...},
198
- * {data: [...], key: ...},
199
- * {data: [...], key: ...},
200
- * ]}
201
- * />
202
- *
203
- * <SectionList
204
- * sections={[ // heterogeneous rendering between sections
205
- * {data: [...], key: ..., renderItem: ...},
206
- * {data: [...], key: ..., renderItem: ...},
207
- * {data: [...], key: ..., renderItem: ...},
208
- * ]}
209
- * />
210
- *
211
- * This is a convenience wrapper around [`<VirtualizedList>`](docs/virtualizedlist.html),
212
- * and thus inherits it's props (as well as those of `ScrollView`) that aren't explicitly listed
213
- * here, along with the following caveats:
214
- *
215
- * - Internal state is not preserved when content scrolls out of the render window. Make sure all
216
- * your data is captured in the item data or external stores like Flux, Redux, or Relay.
217
- * - This is a `PureComponent` which means that it will not re-render if `props` remain shallow-
218
- * equal. Make sure that everything your `renderItem` function depends on is passed as a prop
219
- * (e.g. `extraData`) that is not `===` after updates, otherwise your UI may not update on
220
- * changes. This includes the `data` prop and parent component state.
221
- * - In order to constrain memory and enable smooth scrolling, content is rendered asynchronously
222
- * offscreen. This means it's possible to scroll faster than the fill rate ands momentarily see
223
- * blank content. This is a tradeoff that can be adjusted to suit the needs of each application,
224
- * and we are working on improving it behind the scenes.
225
- * - By default, the list looks for a `key` prop on each item and uses that for the React key.
226
- * Alternatively, you can provide a custom `keyExtractor` prop.
227
- *
228
- */
229
- class SectionList<SectionT: SectionBase<any>>
230
- extends React.PureComponent<DefaultProps, Props<SectionT>, void>
231
- {
232
- props: Props<SectionT>;
233
- static defaultProps: DefaultProps = defaultProps;
234
-
235
- /**
236
- * Scrolls to the item at the specified `sectionIndex` and `itemIndex` (within the section)
237
- * positioned in the viewable area such that `viewPosition` 0 places it at the top (and may be
238
- * covered by a sticky header), 1 at the bottom, and 0.5 centered in the middle. `viewOffset` is a
239
- * fixed number of pixels to offset the final target position, e.g. to compensate for sticky
240
- * headers.
241
- *
242
- * Note: cannot scroll to locations outside the render window without specifying the
243
- * `getItemLayout` prop.
244
- */
245
- scrollToLocation(params: {
246
- animated?: ?boolean,
247
- itemIndex: number,
248
- sectionIndex: number,
249
- viewOffset?: number,
250
- viewPosition?: number,
251
- }) {
252
- this._wrapperListRef.scrollToLocation(params);
253
- }
254
-
255
- /**
256
- * Tells the list an interaction has occured, which should trigger viewability calculations, e.g.
257
- * if `waitForInteractions` is true and the user has not scrolled. This is typically called by
258
- * taps on items or by navigation actions.
259
- */
260
- recordInteraction() {
261
- const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
262
- listRef && listRef.recordInteraction();
263
- }
264
-
265
- /**
266
- * Provides a handle to the underlying scroll responder.
267
- */
268
- getScrollResponder() {
269
- const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
270
- if (listRef) {
271
- return listRef.getScrollResponder();
272
- }
273
- }
274
-
275
- getScrollableNode() {
276
- const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
277
- if (listRef) {
278
- return listRef.getScrollableNode();
279
- }
280
- }
281
-
282
- render() {
283
- const List = this.props.legacyImplementation ? MetroListView : VirtualizedSectionList;
284
- return <List {...this.props} ref={this._captureRef} />;
285
- }
286
-
287
- _wrapperListRef: MetroListView | VirtualizedSectionList<any>;
288
- _captureRef = (ref) => { this._wrapperListRef = ref; };
289
- }
290
-
291
- module.exports = SectionList;