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.
- package/README.md +186 -32
- package/ReactNativeList.podspec +39 -0
- package/android/CMakeLists.txt +48 -0
- package/android/build.gradle +151 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/JHybridUiListModule.cpp +192 -0
- package/android/src/main/cpp/JHybridUiListModule.h +50 -0
- package/android/src/main/cpp/cpp-adapter.cpp +12 -0
- package/android/src/main/java/com/hannojg/reactnativelist/ReactNativeListPackage.kt +27 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListDataSource.kt +146 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListLayout.kt +86 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListModule.kt +116 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListView.kt +410 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridViewHolder.kt +9 -0
- package/android/src/main/java/com/margelo/nitro/reactnativelist/NativeListAdapter.kt +217 -0
- package/ios/DataSource/HybridNativeListDataSource.swift +213 -0
- package/ios/HybridObjects/HybridUiListModule.swift +49 -0
- package/ios/HybridObjects/HybridViewHolder.swift +16 -0
- package/ios/Layout/HybridNativeListLayout.swift +128 -0
- package/ios/Utils/ErrorUtils.h +26 -0
- package/ios/Utils/HybridIOSWorkletsModuleProxyHolder.swift +10 -0
- package/ios/Utils/SurfaceHelper.h +20 -0
- package/ios/Utils/SurfaceHelper.mm +144 -0
- package/ios/Utils/SurfacePresenterRegistry.h +17 -0
- package/ios/Utils/SurfacePresenterRegistry.m +31 -0
- package/ios/Utils/TurboModuleInstaller.h +18 -0
- package/ios/Utils/TurboModuleInstaller.mm +267 -0
- package/ios/Views/HostCell.swift +216 -0
- package/ios/Views/HybridUiListView.swift +695 -0
- package/lib/ReactFabricMirror.d.ts +4 -0
- package/lib/ReactFabricMirror.js +515 -0
- package/lib/UiListModule.d.ts +2 -0
- package/lib/UiListModule.js +2 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +21 -0
- package/lib/privateGlobals.d.ts +14 -0
- package/lib/privateGlobals.js +2 -0
- package/lib/renderer/RenderHelper.d.ts +2 -0
- package/lib/renderer/RenderHelper.js +11 -0
- package/lib/renderer/UiManagerHelper.d.ts +2 -0
- package/lib/renderer/UiManagerHelper.js +2 -0
- package/lib/renderer/fabric/RenderHelper.d.ts +2 -0
- package/lib/renderer/fabric/RenderHelper.js +11 -0
- package/lib/renderer/fabric/UiManagerHelper.d.ts +2 -0
- package/lib/renderer/fabric/UiManagerHelper.js +2 -0
- package/lib/renderer/react/ReactFabricMirror.d.ts +4 -0
- package/lib/renderer/react/ReactFabricMirror.js +515 -0
- package/lib/renderer/react/ReactFabricRenderer.d.ts +3 -0
- package/lib/renderer/react/ReactFabricRenderer.js +9 -0
- package/lib/specs/IOSWorkletsModuleProxyHolder.nitro.d.ts +6 -0
- package/lib/specs/IOSWorkletsModuleProxyHolder.nitro.js +1 -0
- package/lib/specs/UIListModule.nitro.d.ts +9 -0
- package/lib/specs/UIListModule.nitro.js +1 -0
- package/lib/specs/UIManagerHelper.nitro.d.ts +13 -0
- package/lib/specs/UIManagerHelper.nitro.js +1 -0
- package/lib/specs/UiListView.nitro.d.ts +20 -0
- package/lib/specs/UiListView.nitro.js +1 -0
- package/lib/specs/ViewHolder.nitro.d.ts +6 -0
- package/lib/specs/ViewHolder.nitro.js +1 -0
- package/lib/views/List.d.ts +35 -0
- package/lib/views/List.js +225 -0
- package/lib/views/UiListHostComponent.d.ts +2 -0
- package/lib/views/UiListHostComponent.js +3 -0
- package/metro/RendererProxyThreadSwitch.js +66 -0
- package/metro-config.d.ts +1 -0
- package/metro-config.js +124 -0
- package/nitro.json +47 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/ReactNativeList+autolinking.cmake +99 -0
- package/nitrogen/generated/android/ReactNativeList+autolinking.gradle +27 -0
- package/nitrogen/generated/android/ReactNativeListOnLoad.cpp +156 -0
- package/nitrogen/generated/android/ReactNativeListOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JFunc_bool_NativeListItem_NativeListItem.hpp +83 -0
- package/nitrogen/generated/android/c++/JFunc_bool_double_NativeListItem_double.hpp +83 -0
- package/nitrogen/generated/android/c++/JFunc_double_std__string.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.cpp +49 -0
- package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.cpp +63 -0
- package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.cpp +101 -0
- package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.hpp +70 -0
- package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.cpp +49 -0
- package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridUiListViewSpec.cpp +92 -0
- package/nitrogen/generated/android/c++/JHybridUiListViewSpec.hpp +67 -0
- package/nitrogen/generated/android/c++/JHybridViewHolderSpec.cpp +49 -0
- package/nitrogen/generated/android/c++/JHybridViewHolderSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JNativeItemSizeEstimate.hpp +61 -0
- package/nitrogen/generated/android/c++/JNativeLinearListLayoutConfig.hpp +81 -0
- package/nitrogen/generated/android/c++/JNativeLinearListLayoutIOSConfig.hpp +59 -0
- package/nitrogen/generated/android/c++/JNativeListItem.hpp +76 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.hpp +72 -0
- package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.cpp +53 -0
- package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.cpp +53 -0
- package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_NativeListItem_NativeListItem.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_double_NativeListItem_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_double_std__string.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridIOSWorkletsModuleProxyHolderSpec.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeLinearListLayoutSpec.kt +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListDataSourceSpec.kt +87 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListLayoutSpec.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListModuleSpec.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListViewSpec.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridViewHolderSpec.kt +53 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeItemSizeEstimate.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutConfig.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutIOSConfig.kt +51 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeListItem.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/ReactNativeListOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Variant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewManager.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewStateUpdater.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderManager.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/ReactNativeList+autolinking.rb +62 -0
- package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.cpp +162 -0
- package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.hpp +368 -0
- package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Umbrella.hpp +92 -0
- package/nitrogen/generated/ios/ReactNativeListAutolinking.mm +83 -0
- package/nitrogen/generated/ios/ReactNativeListAutolinking.swift +86 -0
- package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.hpp +75 -0
- package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.hpp +132 -0
- package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.hpp +75 -0
- package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.hpp +93 -0
- package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.hpp +121 -0
- package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.hpp +75 -0
- package/nitrogen/generated/ios/c++/views/HybridUiListViewComponent.mm +118 -0
- package/nitrogen/generated/ios/c++/views/HybridViewHolderComponent.mm +118 -0
- package/nitrogen/generated/ios/swift/Func_bool_NativeListItem_NativeListItem.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_bool_double_NativeListItem_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_double_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec_cxx.swift +128 -0
- package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec_cxx.swift +140 -0
- package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec.swift +62 -0
- package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec_cxx.swift +222 -0
- package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec_cxx.swift +128 -0
- package/nitrogen/generated/ios/swift/HybridUiListModuleSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridUiListModuleSpec_cxx.swift +175 -0
- package/nitrogen/generated/ios/swift/HybridUiListViewSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridUiListViewSpec_cxx.swift +227 -0
- package/nitrogen/generated/ios/swift/HybridViewHolderSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridViewHolderSpec_cxx.swift +147 -0
- package/nitrogen/generated/ios/swift/NativeItemSizeEstimate.swift +60 -0
- package/nitrogen/generated/ios/swift/NativeLinearListLayoutConfig.swift +60 -0
- package/nitrogen/generated/ios/swift/NativeLinearListLayoutIOSConfig.swift +35 -0
- package/nitrogen/generated/ios/swift/NativeListItem.swift +75 -0
- package/nitrogen/generated/ios/swift/Variant_NullType__any_HybridIOSWorkletsModuleProxyHolderSpec_.swift +30 -0
- package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.hpp +62 -0
- package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.hpp +72 -0
- package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.hpp +62 -0
- package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.hpp +68 -0
- package/nitrogen/generated/shared/c++/HybridUiListViewSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridUiListViewSpec.hpp +79 -0
- package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridViewHolderSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridViewHolderSpec.hpp +62 -0
- package/nitrogen/generated/shared/c++/NativeItemSizeEstimate.hpp +87 -0
- package/nitrogen/generated/shared/c++/NativeLinearListLayoutConfig.hpp +105 -0
- package/nitrogen/generated/shared/c++/NativeLinearListLayoutIOSConfig.hpp +85 -0
- package/nitrogen/generated/shared/c++/NativeListItem.hpp +101 -0
- package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.cpp +72 -0
- package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.hpp +109 -0
- package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.cpp +72 -0
- package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.hpp +109 -0
- package/nitrogen/generated/shared/json/UiListViewConfig.json +9 -0
- package/nitrogen/generated/shared/json/ViewHolderConfig.json +9 -0
- package/package.json +152 -5
- package/react-native.config.js +16 -0
- package/src/ListDataSource.ts +232 -0
- package/src/ListLayout.ts +95 -0
- package/src/UiListModule.ts +5 -0
- package/src/hooks/useChangeEffect.ts +50 -0
- package/src/index.tsx +49 -0
- package/src/privateGlobals.ts +20 -0
- package/src/renderer/fabric/RenderHelper.ts +29 -0
- package/src/renderer/fabric/UiManagerHelper.ts +5 -0
- package/src/renderer/react/ReactFabricMirror.bundle.js +1984 -0
- package/src/renderer/react/ReactFabricMirror.ts +766 -0
- package/src/renderer/react/ReactFabricRenderer.ts +11 -0
- package/src/specs/IOSWorkletsModuleProxyHolder.nitro.ts +6 -0
- package/src/specs/NativeLinearListLayout.nitro.ts +23 -0
- package/src/specs/NativeListDataSource.nitro.ts +28 -0
- package/src/specs/NativeListLayout.nitro.ts +6 -0
- package/src/specs/UIListModule.nitro.ts +13 -0
- package/src/specs/UIManagerHelper.nitro.ts +34 -0
- package/src/specs/UiListView.nitro.ts +31 -0
- package/src/specs/ViewHolder.nitro.ts +11 -0
- package/src/views/List.tsx +525 -0
- package/src/views/UiListHostComponent.ts +8 -0
- package/FillRateHelper.js +0 -179
- package/FlatList.js +0 -494
- package/LICENSE.md +0 -31
- package/MetroListView.js +0 -166
- package/SectionList.js +0 -291
- package/ViewabilityHelper.js +0 -260
- package/VirtualizeUtils.js +0 -163
- package/VirtualizedList.js +0 -861
- package/VirtualizedSectionList.js +0 -397
- package/index.js +0 -5
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridViewHolderComponent.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridViewHolderComponent.hpp"
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <exception>
|
|
12
|
+
#include <utility>
|
|
13
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
14
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
15
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
16
|
+
#include <react/renderer/core/RawValue.h>
|
|
17
|
+
#include <react/renderer/core/ShadowNode.h>
|
|
18
|
+
#include <react/renderer/core/ComponentDescriptor.h>
|
|
19
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::reactnativelist::views {
|
|
22
|
+
|
|
23
|
+
extern const char HybridViewHolderComponentName[] = "ViewHolder";
|
|
24
|
+
|
|
25
|
+
HybridViewHolderProps::HybridViewHolderProps(const react::PropsParserContext& context,
|
|
26
|
+
const HybridViewHolderProps& sourceProps,
|
|
27
|
+
const react::RawProps& rawProps):
|
|
28
|
+
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
|
|
29
|
+
hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridViewHolderSpec>& /* ref */)>>> {
|
|
30
|
+
try {
|
|
31
|
+
const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
|
|
32
|
+
if (rawValue == nullptr) return sourceProps.hybridRef;
|
|
33
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
34
|
+
return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridViewHolderSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef);
|
|
35
|
+
} catch (const std::exception& exc) {
|
|
36
|
+
throw std::runtime_error(std::string("ViewHolder.hybridRef: ") + exc.what());
|
|
37
|
+
}
|
|
38
|
+
}()) { }
|
|
39
|
+
|
|
40
|
+
bool HybridViewHolderProps::filterObjectKeys(const std::string& propName) {
|
|
41
|
+
switch (hashString(propName)) {
|
|
42
|
+
case hashString("hybridRef"): return true;
|
|
43
|
+
default: return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
HybridViewHolderComponentDescriptor::HybridViewHolderComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
|
|
48
|
+
: ConcreteComponentDescriptor(parameters,
|
|
49
|
+
react::RawPropsParser(/* enableJsiParser */ true)) {}
|
|
50
|
+
|
|
51
|
+
std::shared_ptr<const react::Props> HybridViewHolderComponentDescriptor::cloneProps(const react::PropsParserContext& context,
|
|
52
|
+
const std::shared_ptr<const react::Props>& props,
|
|
53
|
+
react::RawProps rawProps) const {
|
|
54
|
+
// 1. Prepare raw props parser
|
|
55
|
+
rawProps.parse(rawPropsParser_);
|
|
56
|
+
// 2. Copy props with Nitro's cached copy constructor
|
|
57
|
+
return HybridViewHolderShadowNode::Props(context, /* & */ rawProps, props);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#ifdef ANDROID
|
|
61
|
+
void HybridViewHolderComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
|
|
62
|
+
// This is called immediately after `ShadowNode` is created, cloned or in progress.
|
|
63
|
+
// On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
|
|
64
|
+
auto& concreteShadowNode = static_cast<HybridViewHolderShadowNode&>(shadowNode);
|
|
65
|
+
const std::shared_ptr<const HybridViewHolderProps>& constProps = concreteShadowNode.getConcreteSharedProps();
|
|
66
|
+
const std::shared_ptr<HybridViewHolderProps>& props = std::const_pointer_cast<HybridViewHolderProps>(constProps);
|
|
67
|
+
HybridViewHolderState state{props};
|
|
68
|
+
concreteShadowNode.setStateData(std::move(state));
|
|
69
|
+
}
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
} // namespace margelo::nitro::reactnativelist::views
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridViewHolderComponent.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <optional>
|
|
11
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
12
|
+
#include <NitroModules/NitroHash.hpp>
|
|
13
|
+
#include <NitroModules/CachedProp.hpp>
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
18
|
+
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include "HybridViewHolderSpec.hpp"
|
|
21
|
+
#include <functional>
|
|
22
|
+
#include <optional>
|
|
23
|
+
|
|
24
|
+
namespace margelo::nitro::reactnativelist::views {
|
|
25
|
+
|
|
26
|
+
using namespace facebook;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The name of the actual native View.
|
|
30
|
+
*/
|
|
31
|
+
extern const char HybridViewHolderComponentName[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Props for the "ViewHolder" View.
|
|
35
|
+
*/
|
|
36
|
+
class HybridViewHolderProps final: public react::ViewProps {
|
|
37
|
+
public:
|
|
38
|
+
HybridViewHolderProps() = default;
|
|
39
|
+
HybridViewHolderProps(const react::PropsParserContext& context,
|
|
40
|
+
const HybridViewHolderProps& sourceProps,
|
|
41
|
+
const react::RawProps& rawProps);
|
|
42
|
+
|
|
43
|
+
public:
|
|
44
|
+
CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridViewHolderSpec>& /* ref */)>>> hybridRef;
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
static bool filterObjectKeys(const std::string& propName);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* State for the "ViewHolder" View.
|
|
52
|
+
*/
|
|
53
|
+
class HybridViewHolderState final {
|
|
54
|
+
public:
|
|
55
|
+
HybridViewHolderState() = default;
|
|
56
|
+
explicit HybridViewHolderState(const std::shared_ptr<HybridViewHolderProps>& props):
|
|
57
|
+
_props(props) {}
|
|
58
|
+
|
|
59
|
+
public:
|
|
60
|
+
[[nodiscard]]
|
|
61
|
+
const std::shared_ptr<HybridViewHolderProps>& getProps() const {
|
|
62
|
+
return _props;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
#ifdef ANDROID
|
|
67
|
+
HybridViewHolderState(const HybridViewHolderState& /* previousState */, folly::dynamic /* data */) {}
|
|
68
|
+
folly::dynamic getDynamic() const {
|
|
69
|
+
throw std::runtime_error("HybridViewHolderState does not support folly!");
|
|
70
|
+
}
|
|
71
|
+
react::MapBuffer getMapBuffer() const {
|
|
72
|
+
throw std::runtime_error("HybridViewHolderState does not support MapBuffer!");
|
|
73
|
+
};
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
std::shared_ptr<HybridViewHolderProps> _props;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The Shadow Node for the "ViewHolder" View.
|
|
82
|
+
*/
|
|
83
|
+
using HybridViewHolderShadowNode = react::ConcreteViewShadowNode<HybridViewHolderComponentName /* "HybridViewHolder" */,
|
|
84
|
+
HybridViewHolderProps /* custom props */,
|
|
85
|
+
react::ViewEventEmitter /* default */,
|
|
86
|
+
HybridViewHolderState /* custom state */>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The Component Descriptor for the "ViewHolder" View.
|
|
90
|
+
*/
|
|
91
|
+
class HybridViewHolderComponentDescriptor final: public react::ConcreteComponentDescriptor<HybridViewHolderShadowNode> {
|
|
92
|
+
public:
|
|
93
|
+
explicit HybridViewHolderComponentDescriptor(const react::ComponentDescriptorParameters& parameters);
|
|
94
|
+
|
|
95
|
+
public:
|
|
96
|
+
/**
|
|
97
|
+
* A faster path for cloning props - reuses the caching logic from `HybridViewHolderProps`.
|
|
98
|
+
*/
|
|
99
|
+
std::shared_ptr<const react::Props> cloneProps(const react::PropsParserContext& context,
|
|
100
|
+
const std::shared_ptr<const react::Props>& props,
|
|
101
|
+
react::RawProps rawProps) const override;
|
|
102
|
+
#ifdef ANDROID
|
|
103
|
+
void adopt(react::ShadowNode& shadowNode) const override;
|
|
104
|
+
#endif
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/* The actual view for "ViewHolder" needs to be implemented in platform-specific code. */
|
|
108
|
+
|
|
109
|
+
} // namespace margelo::nitro::reactnativelist::views
|
package/package.json
CHANGED
|
@@ -1,8 +1,155 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-list",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
|
+
"description": "React Native List",
|
|
5
|
+
"main": "lib/index",
|
|
6
|
+
"module": "lib/index",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"metro",
|
|
13
|
+
"metro-config.js",
|
|
14
|
+
"metro-config.d.ts",
|
|
15
|
+
"react-native.config.js",
|
|
16
|
+
"lib",
|
|
17
|
+
"nitrogen",
|
|
18
|
+
"android/build.gradle",
|
|
19
|
+
"android/gradle.properties",
|
|
20
|
+
"android/fix-prefab.gradle",
|
|
21
|
+
"android/CMakeLists.txt",
|
|
22
|
+
"android/src",
|
|
23
|
+
"ios/**/*.h",
|
|
24
|
+
"ios/**/*.m",
|
|
25
|
+
"ios/**/*.mm",
|
|
26
|
+
"ios/**/*.cpp",
|
|
27
|
+
"ios/**/*.swift",
|
|
28
|
+
"app.plugin.js",
|
|
29
|
+
"nitro.json",
|
|
30
|
+
"*.podspec",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
36
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
37
|
+
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
38
|
+
"typescript": "tsc",
|
|
39
|
+
"specs": "nitrogen --logLevel=\"debug\"",
|
|
40
|
+
"android": "expo run:android",
|
|
41
|
+
"ios": "expo run:ios",
|
|
42
|
+
"bundle:js": "bun run react-bundler/bundle.ts",
|
|
43
|
+
"bundle:js:prod": "NODE_ENV=production bun run react-bundler/bundle.ts",
|
|
44
|
+
"prepack": "cp ../README.md ./README.md",
|
|
45
|
+
"postpack": "rm ./README.md",
|
|
46
|
+
"release": "release-it"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"nitro"
|
|
51
|
+
],
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/hannojg/react-native-list.git"
|
|
55
|
+
},
|
|
56
|
+
"author": "Hanno Gödecke <hanno@margelo.com> (https://github.com/hannojg)",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/hannojg/react-native-list/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/hannojg/react-native-list#readme",
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@react-native/eslint-config": "0.83.6",
|
|
67
|
+
"eslint": "^8.57.0",
|
|
68
|
+
"eslint-config-prettier": "^9.1.0",
|
|
69
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
70
|
+
"flow-remove-types": "^2.299.0",
|
|
71
|
+
"nitrogen": "catalog:",
|
|
72
|
+
"prettier": "^3.3.3",
|
|
73
|
+
"react": "catalog:",
|
|
74
|
+
"react-native": "catalog:",
|
|
75
|
+
"react-native-nitro-modules": "catalog:",
|
|
76
|
+
"react-native-worklets": "catalog:",
|
|
77
|
+
"react-reconciler": "^0.33.0",
|
|
78
|
+
"release-it": "^20.0.1",
|
|
79
|
+
"typescript": "^5.8.3"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"react": "*",
|
|
83
|
+
"react-native": "*",
|
|
84
|
+
"react-native-worklets": ">=0.10.0",
|
|
85
|
+
"react-native-nitro-modules": "*"
|
|
86
|
+
},
|
|
87
|
+
"eslintConfig": {
|
|
88
|
+
"root": true,
|
|
89
|
+
"extends": [
|
|
90
|
+
"@react-native",
|
|
91
|
+
"prettier"
|
|
92
|
+
],
|
|
93
|
+
"plugins": [
|
|
94
|
+
"prettier"
|
|
95
|
+
],
|
|
96
|
+
"rules": {
|
|
97
|
+
"no-restricted-syntax": [
|
|
98
|
+
"error",
|
|
99
|
+
{
|
|
100
|
+
"selector": "ImportDeclaration[source.value=/ReactFabricMirror(\\.bundle)?(\\.[jt]sx?)?$/]",
|
|
101
|
+
"message": "Import React Fabric mirror through src/renderer/react/ReactFabricRenderer instead."
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"selector": "ExportNamedDeclaration[source.value=/ReactFabricMirror(\\.bundle)?(\\.[jt]sx?)?$/]",
|
|
105
|
+
"message": "Export React Fabric mirror through src/renderer/react/ReactFabricRenderer instead."
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"selector": "ExportAllDeclaration[source.value=/ReactFabricMirror(\\.bundle)?(\\.[jt]sx?)?$/]",
|
|
109
|
+
"message": "Export React Fabric mirror through src/renderer/react/ReactFabricRenderer instead."
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"selector": "CallExpression[callee.name='require'][arguments.0.value=/ReactFabricMirror(\\.bundle)?(\\.[jt]sx?)?$/]",
|
|
113
|
+
"message": "Require React Fabric mirror through src/renderer/react/ReactFabricRenderer instead."
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"selector": "TSImportType Literal[value=/ReactFabricMirror(\\.bundle)?(\\.[jt]sx?)?$/]",
|
|
117
|
+
"message": "Reference React Fabric mirror types through src/renderer/react/ReactFabricRenderer instead."
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"prettier/prettier": [
|
|
121
|
+
"warn",
|
|
122
|
+
{
|
|
123
|
+
"quoteProps": "consistent",
|
|
124
|
+
"singleQuote": true,
|
|
125
|
+
"tabWidth": 2,
|
|
126
|
+
"trailingComma": "es5",
|
|
127
|
+
"useTabs": false
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"overrides": [
|
|
132
|
+
{
|
|
133
|
+
"files": [
|
|
134
|
+
"src/renderer/react/ReactFabricRenderer.ts"
|
|
135
|
+
],
|
|
136
|
+
"rules": {
|
|
137
|
+
"no-restricted-syntax": "off"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"eslintIgnore": [
|
|
143
|
+
"node_modules/",
|
|
144
|
+
"lib/"
|
|
145
|
+
],
|
|
146
|
+
"prettier": {
|
|
147
|
+
"quoteProps": "consistent",
|
|
148
|
+
"singleQuote": true,
|
|
149
|
+
"tabWidth": 2,
|
|
150
|
+
"trailingComma": "es5",
|
|
151
|
+
"useTabs": false,
|
|
152
|
+
"semi": false
|
|
153
|
+
},
|
|
154
|
+
"patchedDependencies": {}
|
|
8
155
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
dependency: {
|
|
5
|
+
platforms: {
|
|
6
|
+
/**
|
|
7
|
+
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
|
|
8
|
+
*/
|
|
9
|
+
ios: {},
|
|
10
|
+
/**
|
|
11
|
+
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
|
+
*/
|
|
13
|
+
android: {},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { AnyMap } from 'react-native-nitro-modules'
|
|
3
|
+
import type { NativeListDataSource } from './specs/NativeListDataSource.nitro'
|
|
4
|
+
import { useEffect, useRef } from 'react'
|
|
5
|
+
import { scheduleOnUI } from 'react-native-worklets'
|
|
6
|
+
|
|
7
|
+
export type ListKey = string
|
|
8
|
+
|
|
9
|
+
export type ListItemSize = {
|
|
10
|
+
width?: number
|
|
11
|
+
height?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ListItem<
|
|
15
|
+
Type = string,
|
|
16
|
+
TData extends AnyMap = AnyMap,
|
|
17
|
+
> = ListItemSize & {
|
|
18
|
+
key: ListKey
|
|
19
|
+
type: Type
|
|
20
|
+
data: TData
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ListItemType<TItem extends ListItem> = TItem['type']
|
|
24
|
+
|
|
25
|
+
export type ListItemForType<
|
|
26
|
+
TItem extends ListItem,
|
|
27
|
+
TType extends ListItemType<TItem>,
|
|
28
|
+
> =
|
|
29
|
+
Extract<TItem, { type: TType }> extends never
|
|
30
|
+
? TItem
|
|
31
|
+
: Extract<TItem, { type: TType }>
|
|
32
|
+
|
|
33
|
+
export type ListContentEqualByType<TItem extends ListItem> = {
|
|
34
|
+
[TType in ListItemType<TItem>]: (
|
|
35
|
+
oldItem: ListItemForType<TItem, TType>,
|
|
36
|
+
newItem: ListItemForType<TItem, TType>
|
|
37
|
+
) => boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ListDataSourceConfig<TItem extends ListItem> = {
|
|
41
|
+
isContentEqualByType?: ListContentEqualByType<TItem>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ListDataSource<TItem extends ListItem> = {
|
|
45
|
+
release(): void
|
|
46
|
+
replaceData(data: readonly TItem[], animated?: boolean): void
|
|
47
|
+
insertItem(index: number, item: TItem): void
|
|
48
|
+
updateItem(index: number, item: TItem): void
|
|
49
|
+
removeItem(index: number): void
|
|
50
|
+
moveItem(fromIndex: number, toIndex: number): void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type ListDataSourceMutation =
|
|
54
|
+
| {
|
|
55
|
+
type: 'replaceData'
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
type: 'removeItem'
|
|
59
|
+
itemKey: string
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
type: 'updateItem'
|
|
63
|
+
previousItemKey: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type ListDataSourceMutationListener = (mutation: ListDataSourceMutation) => void
|
|
67
|
+
|
|
68
|
+
type NativeListDataSourceBacked<TItem extends ListItem> =
|
|
69
|
+
ListDataSource<TItem> & {
|
|
70
|
+
__nativeDataSource: NativeListDataSource
|
|
71
|
+
__setConfig(config: unknown): void
|
|
72
|
+
__addMutationListener(listener: ListDataSourceMutationListener): () => void
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function setContentEqualCallback<TItem extends ListItem>(
|
|
76
|
+
nativeDataSource: NativeListDataSource,
|
|
77
|
+
config: ListDataSourceConfig<TItem>
|
|
78
|
+
) {
|
|
79
|
+
nativeDataSource.setContentEqualCallback((oldItem, newItem) => {
|
|
80
|
+
if (oldItem.type !== newItem.type) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
if (oldItem.width !== newItem.width) {
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
if (oldItem.height !== newItem.height) {
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const type = newItem.type as TItem['type']
|
|
91
|
+
const isContentEqual = config.isContentEqualByType?.[type]
|
|
92
|
+
if (isContentEqual == null) {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return isContentEqual(
|
|
97
|
+
oldItem as unknown as ListItemForType<TItem, typeof type>,
|
|
98
|
+
newItem as unknown as ListItemForType<TItem, typeof type>
|
|
99
|
+
)
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function createListDataSource<TItem extends ListItem>(
|
|
104
|
+
config: ListDataSourceConfig<TItem> = {}
|
|
105
|
+
): ListDataSource<TItem> {
|
|
106
|
+
const nativeDataSource =
|
|
107
|
+
NitroModules.createHybridObject<NativeListDataSource>(
|
|
108
|
+
'NativeListDataSource'
|
|
109
|
+
)
|
|
110
|
+
let currentConfig = config
|
|
111
|
+
let currentItems: TItem[] = []
|
|
112
|
+
const mutationListeners = new Set<ListDataSourceMutationListener>()
|
|
113
|
+
|
|
114
|
+
setContentEqualCallback(nativeDataSource, currentConfig)
|
|
115
|
+
|
|
116
|
+
function notifyMutationListeners(mutation: ListDataSourceMutation) {
|
|
117
|
+
mutationListeners.forEach((listener) => {
|
|
118
|
+
scheduleOnUI(listener, mutation)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const dataSource: NativeListDataSourceBacked<TItem> = {
|
|
123
|
+
__nativeDataSource: nativeDataSource,
|
|
124
|
+
__setConfig(nextConfig: unknown) {
|
|
125
|
+
currentConfig = nextConfig as unknown as ListDataSourceConfig<TItem>
|
|
126
|
+
setContentEqualCallback(nativeDataSource, currentConfig)
|
|
127
|
+
},
|
|
128
|
+
__addMutationListener(listener: ListDataSourceMutationListener) {
|
|
129
|
+
mutationListeners.add(listener)
|
|
130
|
+
return () => {
|
|
131
|
+
mutationListeners.delete(listener)
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
release() {
|
|
135
|
+
currentConfig = {}
|
|
136
|
+
currentItems = []
|
|
137
|
+
mutationListeners.clear()
|
|
138
|
+
nativeDataSource.dispose()
|
|
139
|
+
},
|
|
140
|
+
replaceData(data: readonly TItem[], animated: boolean = false) {
|
|
141
|
+
const nextItems = [...data]
|
|
142
|
+
currentItems = nextItems
|
|
143
|
+
notifyMutationListeners({
|
|
144
|
+
type: 'replaceData',
|
|
145
|
+
})
|
|
146
|
+
nativeDataSource.replaceData(nextItems, animated)
|
|
147
|
+
},
|
|
148
|
+
insertItem(index: number, item: TItem) {
|
|
149
|
+
currentItems.splice(index, 0, item)
|
|
150
|
+
nativeDataSource.insertItem(index, item)
|
|
151
|
+
},
|
|
152
|
+
updateItem(index: number, item: TItem) {
|
|
153
|
+
const previousItem = currentItems[index]
|
|
154
|
+
if (previousItem != null && previousItem.key !== item.key) {
|
|
155
|
+
currentItems[index] = item
|
|
156
|
+
notifyMutationListeners({
|
|
157
|
+
type: 'updateItem',
|
|
158
|
+
previousItemKey: previousItem.key,
|
|
159
|
+
})
|
|
160
|
+
nativeDataSource.updateItem(index, item)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
currentItems[index] = item
|
|
165
|
+
nativeDataSource.updateItem(index, item)
|
|
166
|
+
},
|
|
167
|
+
removeItem(index: number) {
|
|
168
|
+
const removedItems = currentItems.slice(index, index + 1)
|
|
169
|
+
const removedItem = removedItems[0]
|
|
170
|
+
currentItems.splice(index, 1)
|
|
171
|
+
if (removedItem != null) {
|
|
172
|
+
notifyMutationListeners({
|
|
173
|
+
type: 'removeItem',
|
|
174
|
+
itemKey: removedItem.key,
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
nativeDataSource.removeItem(index)
|
|
178
|
+
},
|
|
179
|
+
moveItem(fromIndex: number, toIndex: number) {
|
|
180
|
+
const removedItems = currentItems.slice(fromIndex, fromIndex + 1)
|
|
181
|
+
const movedItem = removedItems[0]
|
|
182
|
+
if (movedItem != null) {
|
|
183
|
+
currentItems.splice(fromIndex, 1)
|
|
184
|
+
currentItems.splice(toIndex, 0, movedItem)
|
|
185
|
+
}
|
|
186
|
+
nativeDataSource.moveItem(fromIndex, toIndex)
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
return dataSource
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function getNativeListDataSource<TItem extends ListItem>(
|
|
193
|
+
dataSource: ListDataSource<TItem>
|
|
194
|
+
): NativeListDataSource {
|
|
195
|
+
const nativeBackedDataSource = dataSource as NativeListDataSourceBacked<TItem>
|
|
196
|
+
return nativeBackedDataSource.__nativeDataSource
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function addListDataSourceMutationListener<TItem extends ListItem>(
|
|
200
|
+
dataSource: ListDataSource<TItem>,
|
|
201
|
+
listener: ListDataSourceMutationListener
|
|
202
|
+
) {
|
|
203
|
+
const nativeBackedDataSource = dataSource as NativeListDataSourceBacked<TItem>
|
|
204
|
+
return nativeBackedDataSource.__addMutationListener(listener)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function useListDataSource<TItem extends ListItem>(
|
|
208
|
+
config: ListDataSourceConfig<TItem> & {
|
|
209
|
+
data: readonly TItem[]
|
|
210
|
+
}
|
|
211
|
+
): ListDataSource<TItem> {
|
|
212
|
+
const dataSourceRef = useRef<ListDataSource<TItem> | null>(null)
|
|
213
|
+
if (dataSourceRef.current == null) {
|
|
214
|
+
dataSourceRef.current = createListDataSource(config)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const dataSource = dataSourceRef.current
|
|
218
|
+
const nativeBackedDataSource = dataSource as NativeListDataSourceBacked<TItem>
|
|
219
|
+
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
nativeBackedDataSource.__setConfig(config)
|
|
222
|
+
dataSource.replaceData(config.data, true)
|
|
223
|
+
}, [config, dataSource, nativeBackedDataSource])
|
|
224
|
+
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
return () => {
|
|
227
|
+
dataSource.release()
|
|
228
|
+
}
|
|
229
|
+
}, [dataSource])
|
|
230
|
+
|
|
231
|
+
return dataSource
|
|
232
|
+
}
|