@lodev09/react-native-true-sheet 3.1.0-beta.0 → 3.1.0-beta.10
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/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +12 -10
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +19 -7
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +119 -208
- package/android/src/main/java/com/lodev09/truesheet/core/RNScreensFragmentObserver.kt +17 -5
- package/android/src/main/jni/CMakeLists.txt +6 -30
- package/android/src/main/res/anim/true_sheet_slide_in.xml +4 -4
- package/android/src/main/res/anim/true_sheet_slide_out.xml +4 -3
- package/ios/TrueSheetContainerView.mm +4 -0
- package/ios/TrueSheetContentView.mm +4 -0
- package/ios/TrueSheetFooterView.mm +4 -0
- package/ios/TrueSheetHeaderView.mm +4 -0
- package/ios/TrueSheetModule.mm +24 -5
- package/ios/TrueSheetView.h +2 -0
- package/ios/TrueSheetView.mm +17 -5
- package/ios/TrueSheetViewController.h +3 -2
- package/ios/TrueSheetViewController.mm +204 -95
- package/lib/module/TrueSheet.js +12 -8
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/navigation/TrueSheetRouter.js +119 -0
- package/lib/module/navigation/TrueSheetRouter.js.map +1 -0
- package/lib/module/navigation/TrueSheetView.js +169 -0
- package/lib/module/navigation/TrueSheetView.js.map +1 -0
- package/lib/module/navigation/createTrueSheetNavigator.js +59 -0
- package/lib/module/navigation/createTrueSheetNavigator.js.map +1 -0
- package/lib/module/navigation/index.js +6 -0
- package/lib/module/navigation/index.js.map +1 -0
- package/lib/module/navigation/types.js +4 -0
- package/lib/module/navigation/types.js.map +1 -0
- package/lib/module/navigation/useTrueSheetNavigation.js +26 -0
- package/lib/module/navigation/useTrueSheetNavigation.js.map +1 -0
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +3 -3
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -1
- package/lib/module/specs/NativeTrueSheetModule.js.map +1 -1
- package/lib/typescript/src/TrueSheet.d.ts +8 -4
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts +57 -0
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts.map +1 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts +10 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts.map +1 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts +35 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts.map +1 -0
- package/lib/typescript/src/navigation/index.d.ts +6 -0
- package/lib/typescript/src/navigation/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/types.d.ts +125 -0
- package/lib/typescript/src/navigation/types.d.ts.map +1 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts +23 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts +4 -2
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts.map +1 -1
- package/package.json +13 -2
- package/src/TrueSheet.tsx +16 -8
- package/src/__mocks__/index.js +6 -5
- package/src/navigation/TrueSheetRouter.ts +172 -0
- package/src/navigation/TrueSheetView.tsx +271 -0
- package/src/navigation/createTrueSheetNavigator.tsx +89 -0
- package/src/navigation/index.ts +14 -0
- package/src/navigation/types.ts +176 -0
- package/src/navigation/useTrueSheetNavigation.ts +28 -0
- package/src/reanimated/ReanimatedTrueSheetProvider.tsx +6 -9
- package/src/specs/NativeTrueSheetModule.ts +4 -2
|
@@ -13,7 +13,9 @@ private const val RN_SCREENS_PACKAGE = "com.swmansion.rnscreens"
|
|
|
13
13
|
*/
|
|
14
14
|
class RNScreensFragmentObserver(
|
|
15
15
|
private val reactContext: ReactContext,
|
|
16
|
+
private val onModalWillPresent: () -> Unit = {},
|
|
16
17
|
private val onModalPresented: () -> Unit,
|
|
18
|
+
private val onModalWillDismiss: () -> Unit = {},
|
|
17
19
|
private val onModalDismissed: () -> Unit
|
|
18
20
|
) {
|
|
19
21
|
private var fragmentLifecycleCallback: FragmentManager.FragmentLifecycleCallbacks? = null
|
|
@@ -27,13 +29,18 @@ class RNScreensFragmentObserver(
|
|
|
27
29
|
val fragmentManager = activity.supportFragmentManager
|
|
28
30
|
|
|
29
31
|
fragmentLifecycleCallback = object : FragmentManager.FragmentLifecycleCallbacks() {
|
|
30
|
-
override fun
|
|
31
|
-
super.
|
|
32
|
+
override fun onFragmentStarted(fm: FragmentManager, fragment: Fragment) {
|
|
33
|
+
super.onFragmentStarted(fm, fragment)
|
|
34
|
+
|
|
35
|
+
if (isModalFragment(fragment) && !activeModalFragments.contains(fragment)) {
|
|
36
|
+
// Notify willPresent before adding to active set
|
|
37
|
+
if (activeModalFragments.isEmpty()) {
|
|
38
|
+
onModalWillPresent()
|
|
39
|
+
}
|
|
32
40
|
|
|
33
|
-
if (isModalFragment(fragment)) {
|
|
34
41
|
activeModalFragments.add(fragment)
|
|
35
42
|
|
|
36
|
-
// Notify
|
|
43
|
+
// Notify didPresent after modal is started
|
|
37
44
|
if (activeModalFragments.size == 1) {
|
|
38
45
|
onModalPresented()
|
|
39
46
|
}
|
|
@@ -44,9 +51,14 @@ class RNScreensFragmentObserver(
|
|
|
44
51
|
super.onFragmentStopped(fm, fragment)
|
|
45
52
|
|
|
46
53
|
if (activeModalFragments.contains(fragment)) {
|
|
54
|
+
// Notify willDismiss before removing from active set
|
|
55
|
+
if (activeModalFragments.size == 1) {
|
|
56
|
+
onModalWillDismiss()
|
|
57
|
+
}
|
|
58
|
+
|
|
47
59
|
activeModalFragments.remove(fragment)
|
|
48
60
|
|
|
49
|
-
// Notify
|
|
61
|
+
// Notify didDismiss after all modals are dismissed
|
|
50
62
|
if (activeModalFragments.isEmpty()) {
|
|
51
63
|
onModalDismissed()
|
|
52
64
|
}
|
|
@@ -28,36 +28,12 @@ target_include_directories(
|
|
|
28
28
|
${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
log
|
|
38
|
-
)
|
|
39
|
-
else()
|
|
40
|
-
target_link_libraries(
|
|
41
|
-
${LIB_TARGET_NAME}
|
|
42
|
-
fbjni
|
|
43
|
-
folly_runtime
|
|
44
|
-
glog
|
|
45
|
-
jsi
|
|
46
|
-
react_codegen_rncore
|
|
47
|
-
react_debug
|
|
48
|
-
react_nativemodule_core
|
|
49
|
-
react_render_core
|
|
50
|
-
react_render_debug
|
|
51
|
-
react_render_graphics
|
|
52
|
-
react_render_mapbuffer
|
|
53
|
-
react_render_componentregistry
|
|
54
|
-
react_utils
|
|
55
|
-
rrc_view
|
|
56
|
-
turbomodulejsijni
|
|
57
|
-
yoga
|
|
58
|
-
log
|
|
59
|
-
)
|
|
60
|
-
endif()
|
|
31
|
+
target_link_libraries(
|
|
32
|
+
${LIB_TARGET_NAME}
|
|
33
|
+
ReactAndroid::reactnative
|
|
34
|
+
ReactAndroid::jsi
|
|
35
|
+
fbjni::fbjni
|
|
36
|
+
)
|
|
61
37
|
|
|
62
38
|
target_include_directories(
|
|
63
39
|
${CMAKE_PROJECT_NAME}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
3
|
<translate
|
|
4
|
-
android:duration="
|
|
4
|
+
android:duration="250"
|
|
5
5
|
android:fromYDelta="20%p"
|
|
6
6
|
android:toYDelta="0"
|
|
7
|
-
android:interpolator="@android:interpolator/
|
|
7
|
+
android:interpolator="@android:interpolator/decelerate_cubic" />
|
|
8
8
|
<alpha
|
|
9
|
-
android:duration="
|
|
9
|
+
android:duration="150"
|
|
10
10
|
android:fromAlpha="0.0"
|
|
11
11
|
android:toAlpha="1.0"
|
|
12
|
-
android:interpolator="@android:interpolator/
|
|
12
|
+
android:interpolator="@android:interpolator/decelerate_cubic" />
|
|
13
13
|
</set>
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
3
|
<translate
|
|
4
|
-
android:duration="
|
|
4
|
+
android:duration="200"
|
|
5
5
|
android:fromYDelta="0"
|
|
6
6
|
android:toYDelta="20%p"
|
|
7
|
-
android:interpolator="@android:interpolator/
|
|
7
|
+
android:interpolator="@android:interpolator/accelerate_cubic" />
|
|
8
8
|
<alpha
|
|
9
9
|
android:duration="150"
|
|
10
|
+
android:startOffset="50"
|
|
10
11
|
android:fromAlpha="1.0"
|
|
11
12
|
android:toAlpha="0.0"
|
|
12
|
-
android:interpolator="@android:interpolator/
|
|
13
|
+
android:interpolator="@android:interpolator/accelerate_cubic" />
|
|
13
14
|
</set>
|
package/ios/TrueSheetModule.mm
CHANGED
|
@@ -46,6 +46,7 @@ RCT_EXPORT_MODULE(TrueSheetModule)
|
|
|
46
46
|
|
|
47
47
|
- (void)presentByRef:(double)viewTag
|
|
48
48
|
index:(double)index
|
|
49
|
+
animated:(BOOL)animated
|
|
49
50
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
50
51
|
reject:(RCTPromiseRejectBlock)reject {
|
|
51
52
|
RCTExecuteOnMainQueue(^{
|
|
@@ -57,7 +58,7 @@ RCT_EXPORT_MODULE(TrueSheetModule)
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
[trueSheetView presentAtIndex:(NSInteger)index
|
|
60
|
-
animated:
|
|
61
|
+
animated:animated
|
|
61
62
|
completion:^(BOOL success, NSError *_Nullable error) {
|
|
62
63
|
if (success) {
|
|
63
64
|
resolve(nil);
|
|
@@ -68,7 +69,10 @@ RCT_EXPORT_MODULE(TrueSheetModule)
|
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
- (void)dismissByRef:(double)viewTag
|
|
72
|
+
- (void)dismissByRef:(double)viewTag
|
|
73
|
+
animated:(BOOL)animated
|
|
74
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
75
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
72
76
|
RCTExecuteOnMainQueue(^{
|
|
73
77
|
TrueSheetView *trueSheetView = [TrueSheetModule getTrueSheetViewByTag:@((NSInteger)viewTag)];
|
|
74
78
|
|
|
@@ -77,7 +81,7 @@ RCT_EXPORT_MODULE(TrueSheetModule)
|
|
|
77
81
|
return;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
[trueSheetView dismissAnimated:
|
|
84
|
+
[trueSheetView dismissAnimated:animated
|
|
81
85
|
completion:^(BOOL success, NSError *_Nullable error) {
|
|
82
86
|
if (success) {
|
|
83
87
|
resolve(nil);
|
|
@@ -92,8 +96,23 @@ RCT_EXPORT_MODULE(TrueSheetModule)
|
|
|
92
96
|
index:(double)index
|
|
93
97
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
94
98
|
reject:(RCTPromiseRejectBlock)reject {
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
RCTExecuteOnMainQueue(^{
|
|
100
|
+
TrueSheetView *trueSheetView = [TrueSheetModule getTrueSheetViewByTag:@((NSInteger)viewTag)];
|
|
101
|
+
|
|
102
|
+
if (!trueSheetView) {
|
|
103
|
+
reject(@"SHEET_NOT_FOUND", [NSString stringWithFormat:@"No sheet found with tag %d", (int)viewTag], nil);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
[trueSheetView resizeToIndex:(NSInteger)index
|
|
108
|
+
completion:^(BOOL success, NSError *_Nullable error) {
|
|
109
|
+
if (success) {
|
|
110
|
+
resolve(nil);
|
|
111
|
+
} else {
|
|
112
|
+
reject(@"RESIZE_FAILED", error.localizedDescription ?: @"Failed to resize sheet", error);
|
|
113
|
+
}
|
|
114
|
+
}];
|
|
115
|
+
});
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
#pragma mark - Helper Methods
|
package/ios/TrueSheetView.h
CHANGED
|
@@ -30,6 +30,8 @@ typedef void (^TrueSheetCompletionBlock)(BOOL success, NSError *_Nullable error)
|
|
|
30
30
|
|
|
31
31
|
- (void)dismissAnimated:(BOOL)animated completion:(nullable TrueSheetCompletionBlock)completion;
|
|
32
32
|
|
|
33
|
+
- (void)resizeToIndex:(NSInteger)index completion:(nullable TrueSheetCompletionBlock)completion;
|
|
34
|
+
|
|
33
35
|
@end
|
|
34
36
|
|
|
35
37
|
NS_ASSUME_NONNULL_END
|
package/ios/TrueSheetView.mm
CHANGED
|
@@ -223,7 +223,7 @@ using namespace facebook::react;
|
|
|
223
223
|
[self->_controller setupSheetDetents];
|
|
224
224
|
[self->_controller applyActiveDetent];
|
|
225
225
|
}];
|
|
226
|
-
[_controller
|
|
226
|
+
[_controller setupDraggable];
|
|
227
227
|
} else if (_initialDetentIndex >= 0) {
|
|
228
228
|
[self presentAtIndex:_initialDetentIndex animated:_initialDetentAnimated completion:nil];
|
|
229
229
|
}
|
|
@@ -356,12 +356,24 @@ using namespace facebook::react;
|
|
|
356
356
|
}];
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
- (void)resizeToIndex:(NSInteger)index completion:(nullable TrueSheetCompletionBlock)completion {
|
|
360
|
+
if (!_controller.isPresented) {
|
|
361
|
+
RCTLogWarn(@"TrueSheet: Cannot resize. Sheet is not presented.");
|
|
362
|
+
if (completion) {
|
|
363
|
+
completion(YES, nil);
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
[self presentAtIndex:index animated:YES completion:completion];
|
|
369
|
+
}
|
|
370
|
+
|
|
359
371
|
#pragma mark - TrueSheetContainerViewDelegate
|
|
360
372
|
|
|
361
373
|
/**
|
|
362
374
|
* Debounced sheet update to handle rapid content/header size changes.
|
|
363
375
|
*/
|
|
364
|
-
- (void)
|
|
376
|
+
- (void)setupSheetDetentsForSizeChange {
|
|
365
377
|
if (!_controller.isPresented || _isSheetUpdatePending)
|
|
366
378
|
return;
|
|
367
379
|
|
|
@@ -371,19 +383,19 @@ using namespace facebook::react;
|
|
|
371
383
|
self->_isSheetUpdatePending = NO;
|
|
372
384
|
|
|
373
385
|
[self->_controller.sheetPresentationController animateChanges:^{
|
|
374
|
-
[self->_controller
|
|
386
|
+
[self->_controller setupSheetDetentsForSizeChange];
|
|
375
387
|
}];
|
|
376
388
|
});
|
|
377
389
|
}
|
|
378
390
|
|
|
379
391
|
- (void)containerViewContentDidChangeSize:(CGSize)newSize {
|
|
380
392
|
_controller.contentHeight = @(newSize.height);
|
|
381
|
-
[self
|
|
393
|
+
[self setupSheetDetentsForSizeChange];
|
|
382
394
|
}
|
|
383
395
|
|
|
384
396
|
- (void)containerViewHeaderDidChangeSize:(CGSize)newSize {
|
|
385
397
|
_controller.headerHeight = @(newSize.height);
|
|
386
|
-
[self
|
|
398
|
+
[self setupSheetDetentsForSizeChange];
|
|
387
399
|
}
|
|
388
400
|
|
|
389
401
|
#pragma mark - TrueSheetViewControllerDelegate
|
|
@@ -69,9 +69,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
69
69
|
- (void)applyActiveDetent;
|
|
70
70
|
- (void)setupActiveDetentWithIndex:(NSInteger)index;
|
|
71
71
|
- (void)resizeToDetentIndex:(NSInteger)index;
|
|
72
|
-
- (void)setupSheetDetents;
|
|
73
72
|
- (void)setupSheetProps;
|
|
74
|
-
- (void)
|
|
73
|
+
- (void)setupSheetDetents;
|
|
74
|
+
- (void)setupSheetDetentsForSizeChange;
|
|
75
|
+
- (void)setupDraggable;
|
|
75
76
|
|
|
76
77
|
@end
|
|
77
78
|
|