react-native-morph-card 0.1.12 → 0.1.13
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.
|
@@ -104,6 +104,9 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
104
104
|
* Capture a snapshot of the source card's children WITHOUT border radius clipping.
|
|
105
105
|
* Like iOS, we want the raw content (e.g. the full rectangular image), not what's
|
|
106
106
|
* visually clipped on screen. The border radius is applied separately during animation.
|
|
107
|
+
*
|
|
108
|
+
* This disables both Android's clipToOutline AND Fresco's RoundingParams (used by
|
|
109
|
+
* React Native's Image component) to capture the full rectangular content.
|
|
107
110
|
*/
|
|
108
111
|
private fun captureSnapshot(): Bitmap {
|
|
109
112
|
val w = width
|
|
@@ -111,20 +114,46 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
111
114
|
val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
|
|
112
115
|
val canvas = Canvas(bitmap)
|
|
113
116
|
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
val
|
|
117
|
+
// Track state to restore: (view, hadClipToOutline, savedRoundingParams)
|
|
118
|
+
data class ViewState(val view: View, val hadClip: Boolean, val roundingParams: Any?)
|
|
119
|
+
val savedStates = mutableListOf<ViewState>()
|
|
120
|
+
|
|
117
121
|
fun disableClipping(view: View) {
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
val hadClip = view.clipToOutline
|
|
123
|
+
var savedRounding: Any? = null
|
|
124
|
+
|
|
125
|
+
// Disable outline clipping
|
|
126
|
+
if (hadClip) {
|
|
120
127
|
view.clipToOutline = false
|
|
121
128
|
}
|
|
129
|
+
|
|
130
|
+
// Disable Fresco RoundingParams on DraweeView (React Native Image components).
|
|
131
|
+
// Uses reflection to avoid a compile-time dependency on Fresco.
|
|
132
|
+
try {
|
|
133
|
+
val getHierarchy = view.javaClass.getMethod("getHierarchy")
|
|
134
|
+
val hierarchy = getHierarchy.invoke(view)
|
|
135
|
+
if (hierarchy != null) {
|
|
136
|
+
val getRounding = hierarchy.javaClass.getMethod("getRoundingParams")
|
|
137
|
+
savedRounding = getRounding.invoke(hierarchy)
|
|
138
|
+
if (savedRounding != null) {
|
|
139
|
+
val roundingClass = Class.forName("com.facebook.drawee.generic.RoundingParams")
|
|
140
|
+
val setRounding = hierarchy.javaClass.getMethod("setRoundingParams", roundingClass)
|
|
141
|
+
setRounding.invoke(hierarchy, null)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch (_: Exception) {}
|
|
145
|
+
|
|
146
|
+
if (hadClip || savedRounding != null) {
|
|
147
|
+
savedStates.add(ViewState(view, hadClip, savedRounding))
|
|
148
|
+
}
|
|
149
|
+
|
|
122
150
|
if (view is ViewGroup) {
|
|
123
151
|
for (i in 0 until view.childCount) {
|
|
124
152
|
disableClipping(view.getChildAt(i))
|
|
125
153
|
}
|
|
126
154
|
}
|
|
127
155
|
}
|
|
156
|
+
|
|
128
157
|
for (i in 0 until childCount) {
|
|
129
158
|
disableClipping(getChildAt(i))
|
|
130
159
|
}
|
|
@@ -138,9 +167,22 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
138
167
|
canvas.restore()
|
|
139
168
|
}
|
|
140
169
|
|
|
141
|
-
// Restore
|
|
142
|
-
for (
|
|
143
|
-
|
|
170
|
+
// Restore all view states
|
|
171
|
+
for (state in savedStates) {
|
|
172
|
+
if (state.hadClip) {
|
|
173
|
+
state.view.clipToOutline = true
|
|
174
|
+
}
|
|
175
|
+
if (state.roundingParams != null) {
|
|
176
|
+
try {
|
|
177
|
+
val getHierarchy = state.view.javaClass.getMethod("getHierarchy")
|
|
178
|
+
val hierarchy = getHierarchy.invoke(state.view)
|
|
179
|
+
if (hierarchy != null) {
|
|
180
|
+
val roundingClass = Class.forName("com.facebook.drawee.generic.RoundingParams")
|
|
181
|
+
val setRounding = hierarchy.javaClass.getMethod("setRoundingParams", roundingClass)
|
|
182
|
+
setRounding.invoke(hierarchy, state.roundingParams)
|
|
183
|
+
}
|
|
184
|
+
} catch (_: Exception) {}
|
|
185
|
+
}
|
|
144
186
|
}
|
|
145
187
|
|
|
146
188
|
return bitmap
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-morph-card",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Native card-to-modal morph transition for React Native. iOS App Store-style expand animation.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|