@whetware/react-native-stroke-text 0.0.3 → 0.0.4
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/CHANGELOG.md +6 -0
- package/android/src/main/java/com/margelo/nitro/stroketext/HybridStrokeTextView.kt +53 -1
- package/android/src/main/java/com/margelo/nitro/stroketext/NitroStrokeTextPackage.kt +2 -2
- package/android/src/main/java/com/margelo/nitro/stroketext/views/StrokeTextViewManager.kt +15 -0
- package/lib/StrokeText.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @whetware/react-native-stroke-text
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`80ded08`](https://github.com/whetware/react-native-stroke-text/commit/80ded08eb3acf84344f56e12b24f74f771726ec1) Thanks [@evelant](https://github.com/evelant)! - Fix handles leak on Android causing crash
|
|
8
|
+
|
|
3
9
|
## 0.0.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
package com.margelo.nitro.stroketext
|
|
2
2
|
|
|
3
3
|
import android.view.View
|
|
4
|
+
import com.facebook.jni.HybridData
|
|
4
5
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
|
+
import com.margelo.nitro.views.RecyclableView
|
|
5
7
|
|
|
6
|
-
class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSpec() {
|
|
8
|
+
class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSpec(), RecyclableView {
|
|
7
9
|
private val strokeTextView = StrokeTextView(context)
|
|
8
10
|
override val view: View = strokeTextView
|
|
9
11
|
|
|
12
|
+
private var isDisposed = false
|
|
13
|
+
|
|
10
14
|
override var text: String = ""
|
|
11
15
|
override var color: String? = null
|
|
12
16
|
override var strokeColor: String? = null
|
|
@@ -34,6 +38,54 @@ class HybridStrokeTextView(context: ThemedReactContext) : HybridStrokeTextViewSp
|
|
|
34
38
|
override var paddingBottom: Double? = null
|
|
35
39
|
override var paddingLeft: Double? = null
|
|
36
40
|
|
|
41
|
+
override fun dispose() {
|
|
42
|
+
if (isDisposed) return
|
|
43
|
+
isDisposed = true
|
|
44
|
+
super.dispose()
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
val hybridDataField = HybridStrokeTextViewSpec::class.java.getDeclaredField("mHybridData")
|
|
48
|
+
hybridDataField.isAccessible = true
|
|
49
|
+
val hybridData = hybridDataField.get(this) as? HybridData ?: return
|
|
50
|
+
|
|
51
|
+
val resetNativeMethod = HybridData::class.java.getDeclaredMethod("resetNative")
|
|
52
|
+
resetNativeMethod.isAccessible = true
|
|
53
|
+
resetNativeMethod.invoke(hybridData)
|
|
54
|
+
} catch (_: Throwable) {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun prepareForRecycle() {
|
|
59
|
+
text = ""
|
|
60
|
+
color = null
|
|
61
|
+
strokeColor = null
|
|
62
|
+
strokeWidth = null
|
|
63
|
+
fontSize = null
|
|
64
|
+
fontWeight = null
|
|
65
|
+
fontFamily = null
|
|
66
|
+
fontStyle = null
|
|
67
|
+
lineHeight = null
|
|
68
|
+
letterSpacing = null
|
|
69
|
+
textAlign = null
|
|
70
|
+
textDecorationLine = null
|
|
71
|
+
textTransform = null
|
|
72
|
+
opacity = null
|
|
73
|
+
allowFontScaling = null
|
|
74
|
+
maxFontSizeMultiplier = null
|
|
75
|
+
includeFontPadding = null
|
|
76
|
+
numberOfLines = null
|
|
77
|
+
ellipsizeMode = null
|
|
78
|
+
padding = null
|
|
79
|
+
paddingVertical = null
|
|
80
|
+
paddingHorizontal = null
|
|
81
|
+
paddingTop = null
|
|
82
|
+
paddingRight = null
|
|
83
|
+
paddingBottom = null
|
|
84
|
+
paddingLeft = null
|
|
85
|
+
|
|
86
|
+
afterUpdate()
|
|
87
|
+
}
|
|
88
|
+
|
|
37
89
|
override fun afterUpdate() {
|
|
38
90
|
val displayMetrics = strokeTextView.resources.displayMetrics
|
|
39
91
|
val resolvedAllowFontScaling = allowFontScaling ?: true
|
|
@@ -7,12 +7,12 @@ import com.facebook.react.BaseReactPackage
|
|
|
7
7
|
import com.facebook.react.ViewManagerOnDemandReactPackage
|
|
8
8
|
import com.facebook.react.bridge.ModuleSpec
|
|
9
9
|
import com.facebook.react.uimanager.ViewManager
|
|
10
|
-
import com.margelo.nitro.stroketext.views.
|
|
10
|
+
import com.margelo.nitro.stroketext.views.StrokeTextViewManager
|
|
11
11
|
|
|
12
12
|
class NitroStrokeTextPackage : BaseReactPackage(), ViewManagerOnDemandReactPackage {
|
|
13
13
|
private val viewManagers: Map<String, ModuleSpec> by lazy {
|
|
14
14
|
mapOf(
|
|
15
|
-
"StrokeTextView" to ModuleSpec.viewManagerSpec {
|
|
15
|
+
"StrokeTextView" to ModuleSpec.viewManagerSpec { StrokeTextViewManager() }
|
|
16
16
|
)
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.margelo.nitro.stroketext.views
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.margelo.nitro.R.id.associated_hybrid_view_tag
|
|
5
|
+
import com.margelo.nitro.stroketext.HybridStrokeTextView
|
|
6
|
+
|
|
7
|
+
class StrokeTextViewManager : HybridStrokeTextViewManager() {
|
|
8
|
+
override fun onDropViewInstance(view: View) {
|
|
9
|
+
val hybridView = view.getTag(associated_hybrid_view_tag) as? HybridStrokeTextView
|
|
10
|
+
view.setTag(associated_hybrid_view_tag, null)
|
|
11
|
+
hybridView?.dispose()
|
|
12
|
+
super.onDropViewInstance(view)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
package/lib/StrokeText.js
CHANGED
|
@@ -88,6 +88,7 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
88
88
|
? undefined
|
|
89
89
|
: nativeProps.ellipsizeMode ?? 'tail';
|
|
90
90
|
const effectiveIncludeFontPadding = nativeProps.includeFontPadding ?? styleIncludeFontPadding ?? false;
|
|
91
|
+
const wrappedHybridRef = React.useMemo(() => (hybridRef ? callback(hybridRef) : undefined), [hybridRef]);
|
|
91
92
|
return (React.createElement(View, { style: [styles.container, containerStyle, strokeInsetMarginStyle] },
|
|
92
93
|
React.createElement(Text, { accessible: false, pointerEvents: "none", numberOfLines: effectiveNumberOfLines, ellipsizeMode: effectiveEllipsizeMode, allowFontScaling: nativeProps.allowFontScaling, maxFontSizeMultiplier: nativeProps.maxFontSizeMultiplier, style: [
|
|
93
94
|
style,
|
|
@@ -102,7 +103,7 @@ export function StrokeText({ text, children, style, hybridRef, ...rest }) {
|
|
|
102
103
|
: { includeFontPadding: effectiveIncludeFontPadding },
|
|
103
104
|
styles.hiddenText,
|
|
104
105
|
] }, resolvedText),
|
|
105
|
-
React.createElement(NativeStrokeTextView, { ...nativeProps, text: resolvedText, color: nativeProps.color ?? toColorString(styleColor), fontSize: nativeProps.fontSize ?? toNumber(styleFontSize), fontWeight: nativeProps.fontWeight ?? toFontWeightString(styleFontWeight), fontFamily: nativeProps.fontFamily ?? styleFontFamily, fontStyle: nativeProps.fontStyle ?? styleFontStyle, lineHeight: nativeProps.lineHeight ?? toNumber(styleLineHeight), letterSpacing: nativeProps.letterSpacing ?? toNumber(styleLetterSpacing), textAlign: nativeProps.textAlign ?? styleTextAlign, textDecorationLine: nativeProps.textDecorationLine ?? styleTextDecorationLine, textTransform: nativeProps.textTransform ?? styleTextTransform, opacity: nativeProps.opacity ?? toNumber(styleOpacity), includeFontPadding: effectiveIncludeFontPadding, numberOfLines: nativeProps.numberOfLines, ellipsizeMode: effectiveEllipsizeMode, paddingTop: baseTop, paddingRight: baseRight, paddingBottom: baseBottom, paddingLeft: baseLeft, hybridRef:
|
|
106
|
+
React.createElement(NativeStrokeTextView, { ...nativeProps, text: resolvedText, color: nativeProps.color ?? toColorString(styleColor), fontSize: nativeProps.fontSize ?? toNumber(styleFontSize), fontWeight: nativeProps.fontWeight ?? toFontWeightString(styleFontWeight), fontFamily: nativeProps.fontFamily ?? styleFontFamily, fontStyle: nativeProps.fontStyle ?? styleFontStyle, lineHeight: nativeProps.lineHeight ?? toNumber(styleLineHeight), letterSpacing: nativeProps.letterSpacing ?? toNumber(styleLetterSpacing), textAlign: nativeProps.textAlign ?? styleTextAlign, textDecorationLine: nativeProps.textDecorationLine ?? styleTextDecorationLine, textTransform: nativeProps.textTransform ?? styleTextTransform, opacity: nativeProps.opacity ?? toNumber(styleOpacity), includeFontPadding: effectiveIncludeFontPadding, numberOfLines: nativeProps.numberOfLines, ellipsizeMode: effectiveEllipsizeMode, paddingTop: baseTop, paddingRight: baseRight, paddingBottom: baseBottom, paddingLeft: baseLeft, hybridRef: wrappedHybridRef, pointerEvents: "none", style: styles.overlay })));
|
|
106
107
|
}
|
|
107
108
|
const styles = StyleSheet.create({
|
|
108
109
|
container: {
|
package/package.json
CHANGED