@onekeyfe/react-native-pager-view 3.0.134 → 3.0.136
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/ios/RNCCollapsiblePagerReleasedStatePolicy.h +12 -0
- package/ios/RNCCollapsiblePagerReleasedStatePolicy.m +14 -0
- package/ios/RNCCollapsiblePagerViewComponentView.mm +6 -1
- package/ios/tests/RNCCollapsiblePagerReleasedStatePolicyTests.mm +37 -0
- package/package.json +2 -2
- package/react-native-pager-view.podspec +5 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
// Keep the dictionary unspecialized: NSMutableDictionary generics are invariant,
|
|
6
|
+
// so Objective-C++ callers with a concrete value type would fail to compile.
|
|
7
|
+
FOUNDATION_EXPORT void RNCPruneReleasedPageStates(
|
|
8
|
+
NSMutableDictionary *releasedStates,
|
|
9
|
+
NSArray<NSString *> *validPageKeys
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import "RNCCollapsiblePagerReleasedStatePolicy.h"
|
|
2
|
+
|
|
3
|
+
void RNCPruneReleasedPageStates(
|
|
4
|
+
NSMutableDictionary *releasedStates,
|
|
5
|
+
NSArray<NSString *> *validPageKeys
|
|
6
|
+
)
|
|
7
|
+
{
|
|
8
|
+
NSSet<NSString *> *validKeys = [NSSet setWithArray:validPageKeys];
|
|
9
|
+
for (NSString *pageKey in releasedStates.allKeys) {
|
|
10
|
+
if (![validKeys containsObject:pageKey]) {
|
|
11
|
+
[releasedStates removeObjectForKey:pageKey];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "RNCCollapsiblePagerViewComponentView.h"
|
|
2
|
+
#import "RNCCollapsiblePagerReleasedStatePolicy.h"
|
|
2
3
|
|
|
3
4
|
#import <react/renderer/components/pagerview/ComponentDescriptors.h>
|
|
4
5
|
#import <react/renderer/components/pagerview/EventEmitters.h>
|
|
@@ -1876,7 +1877,11 @@ static void RNCLogNativeTabScrollBoundary(NSString *owner,
|
|
|
1876
1877
|
NSString *json = RCTNSStringFromString(newViewProps.pageKeys);
|
|
1877
1878
|
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
|
1878
1879
|
id parsed = data == nil ? nil : [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
1879
|
-
|
|
1880
|
+
NSArray<NSString *> *nextPageKeys = [parsed isKindOfClass:NSArray.class] ? parsed : @[];
|
|
1881
|
+
// Stable keys keep their released identity across reorders. A missing key
|
|
1882
|
+
// represents an unmounted React page and must not be reused by a later page.
|
|
1883
|
+
RNCPruneReleasedPageStates(_releasedPageScrollStates, nextPageKeys);
|
|
1884
|
+
_pageKeys = nextPageKeys;
|
|
1880
1885
|
}
|
|
1881
1886
|
if (_needsPropsReapply || oldViewProps.retainedPages != newViewProps.retainedPages) {
|
|
1882
1887
|
_retainedPages = RCTNSStringFromString(newViewProps.retainedPages);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import <XCTest/XCTest.h>
|
|
2
|
+
|
|
3
|
+
#import "RNCCollapsiblePagerReleasedStatePolicy.h"
|
|
4
|
+
|
|
5
|
+
@interface RNCCollapsiblePagerReleasedStatePolicyTests : XCTestCase
|
|
6
|
+
@end
|
|
7
|
+
|
|
8
|
+
@implementation RNCCollapsiblePagerReleasedStatePolicyTests
|
|
9
|
+
|
|
10
|
+
- (void)testPrunesRemovedKeysAndKeepsStableKeysAcrossReorders
|
|
11
|
+
{
|
|
12
|
+
NSObject *alpha = [NSObject new];
|
|
13
|
+
NSObject *beta = [NSObject new];
|
|
14
|
+
// A concrete value type in Objective-C++ mirrors the component view call site.
|
|
15
|
+
NSMutableDictionary<NSString *, NSObject *> *releasedStates = [@{
|
|
16
|
+
@"alpha": alpha,
|
|
17
|
+
@"beta": beta,
|
|
18
|
+
} mutableCopy];
|
|
19
|
+
|
|
20
|
+
RNCPruneReleasedPageStates(releasedStates, @[@"beta", @"gamma"]);
|
|
21
|
+
|
|
22
|
+
XCTAssertEqualObjects(releasedStates, (@{ @"beta": beta }));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (void)testClearsEveryReleasedStateWhenAllPagesUnmount
|
|
26
|
+
{
|
|
27
|
+
NSMutableDictionary<NSString *, id> *releasedStates = [@{
|
|
28
|
+
@"page-0": [NSObject new],
|
|
29
|
+
@"page-1": [NSObject new],
|
|
30
|
+
} mutableCopy];
|
|
31
|
+
|
|
32
|
+
RNCPruneReleasedPageStates(releasedStates, @[]);
|
|
33
|
+
|
|
34
|
+
XCTAssertEqual(releasedStates.count, 0u);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-pager-view",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.136",
|
|
4
4
|
"description": "React Native wrapper for Android and iOS ViewPager",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"typescript": "^5.9.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@onekeyfe/react-native-native-logger": "3.0.
|
|
69
|
+
"@onekeyfe/react-native-native-logger": "3.0.136",
|
|
70
70
|
"react": "*",
|
|
71
71
|
"react-native": "*"
|
|
72
72
|
},
|
|
@@ -14,6 +14,11 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.source = { :git => "https://github.com/nicholasxuu/app-modules.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
s.exclude_files = "ios/tests/**/*"
|
|
18
|
+
|
|
19
|
+
s.test_spec "Tests" do |test_spec|
|
|
20
|
+
test_spec.source_files = "ios/tests/**/*.{m,mm}"
|
|
21
|
+
end
|
|
17
22
|
|
|
18
23
|
install_modules_dependencies(s)
|
|
19
24
|
|