react-native-sheet2 6.1.19 → 7.12.5
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 +754 -80
- package/{Sheet.podspec → Sheet2.podspec} +2 -2
- package/android/build.gradle +2 -25
- package/android/check.jks +0 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
- package/android/src/main/java/com/sheet2/AppFittedSheet.kt +432 -0
- package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
- package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
- package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +37 -4
- package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
- package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +170 -0
- package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
- package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
- package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
- package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
- package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
- package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
- package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
- package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
- package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
- package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
- package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
- package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
- package/android/src/main/jni/CMakeLists.txt +72 -0
- package/android/src/main/jni/SheetViewSpec.h +40 -0
- package/ios/FittedSheets/SheetOptions.swift +5 -0
- package/ios/FittedSheets/SheetTransition.swift +83 -4
- package/ios/FittedSheets/SheetViewController.swift +222 -24
- package/ios/HostFittedSheet.swift +440 -51
- package/ios/SheetModule.h +5 -4
- package/ios/SheetModule.mm +11 -1
- package/ios/SheetTreeLog.swift +52 -0
- package/ios/SheetView.mm +118 -31
- package/ios/SheetViewComponentDescriptor.h +24 -0
- package/ios/SheetViewShadowNode.cpp +17 -0
- package/ios/SheetViewShadowNode.h +37 -0
- package/ios/SheetViewState.h +54 -0
- package/package.json +44 -74
- package/react-native.config.js +6 -4
- package/src/FittedSheet.tsx +131 -71
- package/src/GlobalSheetView.tsx +209 -0
- package/src/NativeSheet.ts +4 -0
- package/src/PublicSheetView.tsx +2 -1
- package/src/SheetTreeLog.ts +39 -0
- package/src/SheetViewNativeComponent.ts +25 -4
- package/src/index.tsx +29 -4
- package/src/logger.ts +16 -0
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
- package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
- package/android/generated/jni/CMakeLists.txt +0 -36
- package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
- package/android/generated/jni/RNSheetViewSpec.h +0 -31
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
- package/android/src/main/java/com/sheet/SheetView.kt +0 -5
- package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
- package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
- package/ios/generated/RNSheetViewSpec/Props.h +0 -36
- package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
- package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
- package/ios/generated/RNSheetViewSpec/States.h +0 -29
- package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/ios/generated/RNSheetViewSpecJSI.h +0 -98
- package/lib/module/FittedSheet.js +0 -153
- package/lib/module/FittedSheet.js.map +0 -1
- package/lib/module/NativeSheet.ts +0 -17
- package/lib/module/PublicSheetView.js +0 -48
- package/lib/module/PublicSheetView.js.map +0 -1
- package/lib/module/SheetViewNativeComponent.ts +0 -31
- package/lib/module/index.js +0 -17
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/FittedSheet.d.ts +0 -51
- package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
- package/lib/typescript/src/NativeSheet.d.ts +0 -16
- package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
- package/lib/typescript/src/PublicSheetView.d.ts +0 -12
- package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
- package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
- package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -12
- package/lib/typescript/src/index.d.ts.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import com.facebook.react.bridge.ReactContext
|
|
8
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Every place where this library moves a view React Native believes it owns.
|
|
12
|
+
*
|
|
13
|
+
* The mounting crashes worth chasing carry no frame of ours: on Android the
|
|
14
|
+
* stack between `ViewGroupManager.addView` and `ViewGroup.addInArray` is React
|
|
15
|
+
* Native and the framework only ("addViewAt: failed to insert view [child] into
|
|
16
|
+
* parent [parent] at index N", caused by "IndexOutOfBoundsException: index=N
|
|
17
|
+
* count=0"). So the only way to tell afterwards whether a sheet was involved is
|
|
18
|
+
* to say so ourselves, naming the views by the id React Native uses as the tag —
|
|
19
|
+
* which is exactly what that message carries.
|
|
20
|
+
*
|
|
21
|
+
* Entries go to logcat, to a small in-memory ring for a local session, and — when
|
|
22
|
+
* a listener is registered from JS — to the app, which is expected to turn them
|
|
23
|
+
* into breadcrumbs. Breadcrumbs are what survives into a native crash report.
|
|
24
|
+
*/
|
|
25
|
+
object SheetTreeLog {
|
|
26
|
+
private const val TAG = "Sheet2Tree"
|
|
27
|
+
private const val EVENT = "sheet2:tree"
|
|
28
|
+
private const val CAPACITY = 32
|
|
29
|
+
|
|
30
|
+
private val entries = ArrayDeque<String>()
|
|
31
|
+
|
|
32
|
+
@Volatile
|
|
33
|
+
var logsEnabled = false
|
|
34
|
+
|
|
35
|
+
fun debug(message: String) {
|
|
36
|
+
if (logsEnabled) Log.d(TAG, message)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun log(context: Context?, op: String, details: String) {
|
|
40
|
+
val entry = "$op $details"
|
|
41
|
+
|
|
42
|
+
synchronized(entries) {
|
|
43
|
+
if (entries.size == CAPACITY) entries.removeFirst()
|
|
44
|
+
entries.addLast(entry)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
debug(entry)
|
|
48
|
+
emit(context, entry)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The tag React Native knows the view by, or "-" when there is no view. */
|
|
52
|
+
fun tag(view: View?): String = view?.let { "${it.id}" } ?: "-"
|
|
53
|
+
|
|
54
|
+
fun childTags(parent: ViewGroup?): String {
|
|
55
|
+
if (parent == null) return "-"
|
|
56
|
+
val count = parent.childCount
|
|
57
|
+
if (count == 0) return "none"
|
|
58
|
+
|
|
59
|
+
return (0 until count).joinToString(",") { "${parent.getChildAt(it).id}" }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun snapshot(): List<String> = synchronized(entries) { entries.toList() }
|
|
63
|
+
|
|
64
|
+
private fun emit(context: Context?, entry: String) {
|
|
65
|
+
val reactContext = context as? ReactContext ?: return
|
|
66
|
+
if (!reactContext.hasActiveReactInstance()) return
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
reactContext
|
|
70
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
71
|
+
.emit(EVENT, entry)
|
|
72
|
+
} catch (error: Throwable) {
|
|
73
|
+
// A sheet can be torn down while the instance is going away; diagnostics
|
|
74
|
+
// must never be the reason something crashes.
|
|
75
|
+
debug("emit failed: ${error.message}")
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Color
|
|
@@ -8,7 +8,6 @@ import android.view.Window
|
|
|
8
8
|
import android.view.WindowInsetsController
|
|
9
9
|
import androidx.core.graphics.toColorInt
|
|
10
10
|
import com.facebook.react.bridge.ReadableMap
|
|
11
|
-
import com.facebook.react.uimanager.PixelUtil
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
fun ReadableMap?.bool(value: String, default: Boolean): Boolean {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
3
|
+
|
|
4
|
+
# The React Native gradle plugin uses the codegen name of the library
|
|
5
|
+
# (`codegenConfig.name` in package.json = `SheetViewSpec`) as the build-target
|
|
6
|
+
# stem and expects a library target called `react_codegen_SheetViewSpec`.
|
|
7
|
+
# Our custom CMakeLists replaces the auto-generated one so we can compile
|
|
8
|
+
# our custom C++ sources alongside the codegen-produced files AND put our
|
|
9
|
+
# `jni/` directory earlier in the include path (this shadows the default
|
|
10
|
+
# `<SheetViewSpec.h>` and `<react/renderer/components/SheetViewSpec/...>`
|
|
11
|
+
# headers generated by codegen when they would otherwise pull in the
|
|
12
|
+
# default-typedef ShadowNode).
|
|
13
|
+
set(LIB_LITERAL SheetViewSpec)
|
|
14
|
+
set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL})
|
|
15
|
+
|
|
16
|
+
set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
|
17
|
+
set(LIB_CUSTOM_CPP_DIR ${LIB_ANDROID_DIR}/src/main/cpp)
|
|
18
|
+
set(LIB_CUSTOM_COMPONENTS_DIR
|
|
19
|
+
${LIB_CUSTOM_CPP_DIR}/react/renderer/components/${LIB_LITERAL})
|
|
20
|
+
set(LIB_ANDROID_GENERATED_JNI_DIR
|
|
21
|
+
${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
|
|
22
|
+
set(LIB_ANDROID_GENERATED_COMPONENTS_DIR
|
|
23
|
+
${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
|
|
24
|
+
|
|
25
|
+
add_compile_options(
|
|
26
|
+
-fexceptions
|
|
27
|
+
-frtti
|
|
28
|
+
-std=c++20
|
|
29
|
+
-Wall
|
|
30
|
+
-Wpedantic
|
|
31
|
+
-Wno-gnu-zero-variadic-macro-arguments
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS
|
|
35
|
+
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
|
36
|
+
${LIB_CUSTOM_COMPONENTS_DIR}/*.cpp
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS
|
|
40
|
+
${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp
|
|
41
|
+
${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
add_library(
|
|
45
|
+
${LIB_TARGET_NAME}
|
|
46
|
+
SHARED
|
|
47
|
+
${LIB_CUSTOM_SRCS}
|
|
48
|
+
${LIB_CODEGEN_SRCS}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Order matters: our `jni` and `cpp` dirs must come BEFORE the codegen
|
|
52
|
+
# generated directory so our custom `SheetViewSpec.h` shadows the generated
|
|
53
|
+
# one and our custom component-descriptor include path wins.
|
|
54
|
+
target_include_directories(
|
|
55
|
+
${LIB_TARGET_NAME}
|
|
56
|
+
PUBLIC
|
|
57
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
58
|
+
${LIB_CUSTOM_CPP_DIR}
|
|
59
|
+
${LIB_ANDROID_GENERATED_JNI_DIR}
|
|
60
|
+
${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
${LIB_TARGET_NAME}
|
|
65
|
+
ReactAndroid::reactnative
|
|
66
|
+
ReactAndroid::jsi
|
|
67
|
+
fbjni::fbjni
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
if(COMMAND target_compile_reactnative_options)
|
|
71
|
+
target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
|
|
72
|
+
endif()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
4
|
+
#include <ReactCommon/TurboModule.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom autolinking header for the SheetViewSpec library.
|
|
9
|
+
*
|
|
10
|
+
* The React Native gradle plugin generates a default `SheetViewSpec.h` at
|
|
11
|
+
* `android/build/generated/source/codegen/jni/SheetViewSpec.h`. By configuring
|
|
12
|
+
* our own `CMakeLists.txt` with an include directory that comes BEFORE the
|
|
13
|
+
* generated one, `autolinking.cpp` finds this file first and therefore sees
|
|
14
|
+
* our custom `SheetViewComponentDescriptor` declaration — which is defined in
|
|
15
|
+
* the library's `common/cpp` area and subclasses the codegen-provided
|
|
16
|
+
* ViewShadowNode with a custom `getContentOriginOffset` override.
|
|
17
|
+
*
|
|
18
|
+
* See react-native-screens' `rnscreens.h` for the same pattern.
|
|
19
|
+
*/
|
|
20
|
+
#include <react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h>
|
|
21
|
+
|
|
22
|
+
namespace facebook::react {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* TurboModule provider declaration — codegen generates the implementation at
|
|
26
|
+
* `build/generated/source/codegen/jni/SheetViewSpec-generated.cpp`; we only
|
|
27
|
+
* repeat the prototype here so that consumers of this header (autolinking.cpp)
|
|
28
|
+
* can resolve both our ComponentDescriptor include AND the TurboModule symbol.
|
|
29
|
+
*/
|
|
30
|
+
JSI_EXPORT
|
|
31
|
+
std::shared_ptr<TurboModule> SheetViewSpec_ModuleProvider(
|
|
32
|
+
const std::string& moduleName,
|
|
33
|
+
const JavaTurboModule::InitParams& params);
|
|
34
|
+
|
|
35
|
+
class JSI_EXPORT NativeSheetSpecJSI : public JavaTurboModule {
|
|
36
|
+
public:
|
|
37
|
+
NativeSheetSpecJSI(const JavaTurboModule::InitParams& params);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace facebook::react
|
|
@@ -44,6 +44,11 @@ public struct SheetOptions {
|
|
|
44
44
|
public var horizontalPadding: CGFloat = 0
|
|
45
45
|
public var maxWidth: CGFloat?
|
|
46
46
|
|
|
47
|
+
/// Present the sheet centered on screen instead of pinned to the bottom.
|
|
48
|
+
public var centered: Bool = false
|
|
49
|
+
/// When `centered`, slide the card up into place instead of fade+scale.
|
|
50
|
+
public var centerSlide: Bool = false
|
|
51
|
+
|
|
47
52
|
public var isRubberBandEnabled: Bool = false
|
|
48
53
|
|
|
49
54
|
/// Experimental flag that attempts to shrink the nested presentations more each time a new sheet is presented. This must be set before any sheet is presented.
|
|
@@ -50,15 +50,77 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
|
|
50
50
|
sheet.contentViewController.updatePreferredHeight()
|
|
51
51
|
sheet.resize(to: sheet.currentSize, animated: false)
|
|
52
52
|
let contentView = sheet.contentViewController.contentView
|
|
53
|
+
|
|
54
|
+
if self.options.centered && !self.options.centerSlide {
|
|
55
|
+
// Centered fade: the card is centered by constraint, so fade +
|
|
56
|
+
// scale it in (0.9 -> 1.0) and fade the overlay in.
|
|
57
|
+
contentView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
|
58
|
+
contentView.alpha = 0
|
|
59
|
+
sheet.overlayView.alpha = 0
|
|
60
|
+
|
|
61
|
+
UIView.performWithoutAnimation {
|
|
62
|
+
sheet.view.layoutIfNeeded()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
UIView.animate(
|
|
66
|
+
withDuration: self.options.transitionDuration,
|
|
67
|
+
delay: 0,
|
|
68
|
+
options: [.curveEaseOut],
|
|
69
|
+
animations: {
|
|
70
|
+
contentView.transform = .identity
|
|
71
|
+
contentView.alpha = 1
|
|
72
|
+
sheet.overlayView.alpha = 1
|
|
73
|
+
},
|
|
74
|
+
completion: { _ in
|
|
75
|
+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if self.options.centered {
|
|
82
|
+
// Centered slide: start the card fully below the bottom edge and
|
|
83
|
+
// slide it up into its centered resting position — symmetric with
|
|
84
|
+
// the centered dismiss (which slides it back down off the bottom).
|
|
85
|
+
// The offset is measured AFTER layout so it never reads a stale or
|
|
86
|
+
// zero height; reading it before layout was making the slide
|
|
87
|
+
// collapse into a fade on some presentations ("every other time").
|
|
88
|
+
UIView.performWithoutAnimation {
|
|
89
|
+
sheet.view.layoutIfNeeded()
|
|
90
|
+
}
|
|
91
|
+
let cardTop = contentView.convert(contentView.bounds, to: sheet.view).minY
|
|
92
|
+
let startOffset = max(contentView.bounds.height, sheet.view.bounds.height - cardTop)
|
|
93
|
+
contentView.transform = CGAffineTransform(translationX: 0, y: startOffset)
|
|
94
|
+
sheet.overlayView.alpha = 0
|
|
95
|
+
|
|
96
|
+
UIView.animate(
|
|
97
|
+
withDuration: self.options.transitionDuration,
|
|
98
|
+
delay: 0,
|
|
99
|
+
usingSpringWithDamping: 0.9,
|
|
100
|
+
initialSpringVelocity: 0,
|
|
101
|
+
options: [.curveEaseOut],
|
|
102
|
+
animations: {
|
|
103
|
+
contentView.transform = .identity
|
|
104
|
+
sheet.overlayView.alpha = 1
|
|
105
|
+
},
|
|
106
|
+
completion: { _ in
|
|
107
|
+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Slide-up (bottom presentation). For centered mode the branch above
|
|
114
|
+
// handles the slide; this is the original bottom-sheet path.
|
|
53
115
|
contentView.transform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
|
|
54
116
|
sheet.overlayView.alpha = 0
|
|
55
|
-
|
|
117
|
+
|
|
56
118
|
let heightPercent = contentView.bounds.height / UIScreen.main.bounds.height
|
|
57
|
-
|
|
119
|
+
|
|
58
120
|
UIView.performWithoutAnimation {
|
|
59
121
|
sheet.view.layoutIfNeeded()
|
|
60
122
|
}
|
|
61
|
-
|
|
123
|
+
|
|
62
124
|
// Use a normal animation to animate the shadown and background view
|
|
63
125
|
UIView.animate(withDuration: self.options.transitionDuration * 0.6, delay: 0, options: [.curveEaseOut], animations: {
|
|
64
126
|
if self.options.shrinkPresentingViewController {
|
|
@@ -91,10 +153,27 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
|
|
91
153
|
containerView.addSubview(sheet.view)
|
|
92
154
|
let contentView = sheet.contentViewController.contentView
|
|
93
155
|
|
|
156
|
+
let dismissTransform: CGAffineTransform
|
|
157
|
+
if self.options.centered {
|
|
158
|
+
// The card sits in the vertical center, so translating it down
|
|
159
|
+
// by only its own height leaves it stranded mid-screen while the
|
|
160
|
+
// overlay has already faded out. Instead slide it all the way
|
|
161
|
+
// off the bottom of the screen — exactly like the bottom sheet —
|
|
162
|
+
// so the dim and the card leave the screen together. The offset
|
|
163
|
+
// is measured from the card's CURRENT on-screen top (which
|
|
164
|
+
// already includes any swipe-drag transform), so a pan-initiated
|
|
165
|
+
// dismiss continues smoothly from the finger's position.
|
|
166
|
+
let cardTop = contentView.convert(contentView.bounds, to: sheet.view).minY
|
|
167
|
+
let offset = max(contentView.bounds.height, sheet.view.bounds.height - cardTop)
|
|
168
|
+
dismissTransform = CGAffineTransform(translationX: 0, y: offset)
|
|
169
|
+
} else {
|
|
170
|
+
dismissTransform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
|
|
171
|
+
}
|
|
172
|
+
|
|
94
173
|
self.restorePresentor(
|
|
95
174
|
presenter,
|
|
96
175
|
animations: {
|
|
97
|
-
contentView.transform =
|
|
176
|
+
contentView.transform = dismissTransform
|
|
98
177
|
sheet.overlayView.alpha = 0
|
|
99
178
|
}, completion: { _ in
|
|
100
179
|
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|