react-native-morph-card 0.1.12 → 0.1.14
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,53 @@ 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
|
+
Log.d(TAG, "captureSnapshot: visiting ${view.javaClass.name} clipToOutline=$hadClip size=${view.width}x${view.height}")
|
|
126
|
+
|
|
127
|
+
// Disable outline clipping
|
|
128
|
+
if (hadClip) {
|
|
120
129
|
view.clipToOutline = false
|
|
121
130
|
}
|
|
131
|
+
|
|
132
|
+
// Disable Fresco RoundingParams on DraweeView (React Native Image components).
|
|
133
|
+
// Uses reflection to avoid a compile-time dependency on Fresco.
|
|
134
|
+
try {
|
|
135
|
+
val getHierarchy = view.javaClass.getMethod("getHierarchy")
|
|
136
|
+
val hierarchy = getHierarchy.invoke(view)
|
|
137
|
+
if (hierarchy != null) {
|
|
138
|
+
Log.d(TAG, "captureSnapshot: found hierarchy ${hierarchy.javaClass.name}")
|
|
139
|
+
val getRounding = hierarchy.javaClass.getMethod("getRoundingParams")
|
|
140
|
+
savedRounding = getRounding.invoke(hierarchy)
|
|
141
|
+
Log.d(TAG, "captureSnapshot: roundingParams=$savedRounding")
|
|
142
|
+
if (savedRounding != null) {
|
|
143
|
+
val roundingClass = Class.forName("com.facebook.drawee.generic.RoundingParams")
|
|
144
|
+
val setRounding = hierarchy.javaClass.getMethod("setRoundingParams", roundingClass)
|
|
145
|
+
setRounding.invoke(hierarchy, null)
|
|
146
|
+
Log.d(TAG, "captureSnapshot: disabled Fresco rounding")
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch (e: Exception) {
|
|
150
|
+
Log.d(TAG, "captureSnapshot: reflection skip for ${view.javaClass.simpleName}: ${e.javaClass.simpleName}")
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (hadClip || savedRounding != null) {
|
|
154
|
+
savedStates.add(ViewState(view, hadClip, savedRounding))
|
|
155
|
+
}
|
|
156
|
+
|
|
122
157
|
if (view is ViewGroup) {
|
|
123
158
|
for (i in 0 until view.childCount) {
|
|
124
159
|
disableClipping(view.getChildAt(i))
|
|
125
160
|
}
|
|
126
161
|
}
|
|
127
162
|
}
|
|
163
|
+
|
|
128
164
|
for (i in 0 until childCount) {
|
|
129
165
|
disableClipping(getChildAt(i))
|
|
130
166
|
}
|
|
@@ -138,9 +174,22 @@ class MorphCardSourceView(context: Context) : ReactViewGroup(context) {
|
|
|
138
174
|
canvas.restore()
|
|
139
175
|
}
|
|
140
176
|
|
|
141
|
-
// Restore
|
|
142
|
-
for (
|
|
143
|
-
|
|
177
|
+
// Restore all view states
|
|
178
|
+
for (state in savedStates) {
|
|
179
|
+
if (state.hadClip) {
|
|
180
|
+
state.view.clipToOutline = true
|
|
181
|
+
}
|
|
182
|
+
if (state.roundingParams != null) {
|
|
183
|
+
try {
|
|
184
|
+
val getHierarchy = state.view.javaClass.getMethod("getHierarchy")
|
|
185
|
+
val hierarchy = getHierarchy.invoke(state.view)
|
|
186
|
+
if (hierarchy != null) {
|
|
187
|
+
val roundingClass = Class.forName("com.facebook.drawee.generic.RoundingParams")
|
|
188
|
+
val setRounding = hierarchy.javaClass.getMethod("setRoundingParams", roundingClass)
|
|
189
|
+
setRounding.invoke(hierarchy, state.roundingParams)
|
|
190
|
+
}
|
|
191
|
+
} catch (_: Exception) {}
|
|
192
|
+
}
|
|
144
193
|
}
|
|
145
194
|
|
|
146
195
|
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.14",
|
|
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",
|