我要创建带有轮廓文字的标签。
我的方法如下:
class NativeOutlinedTextViewManager: ReactTextViewManager() {
override fun getName(): String {
return "NativeOutlinedTextView"
}
override fun createViewInstance(context: ThemedReactContext): ReactTextView {
return NativeOutlinedReactTextView(context)
}
}
class NativeOutlinedReactTextView(context: Context): ReactTextView(context) {
override fun setText(update: ReactTextUpdate) {
update.text.setSpan(OutlineSpan(), 0, update.text.length - 1, 0)
super.setText(update)
}
}
class OutlineSpan : CharacterStyle() {
override fun updateDrawState(paint: TextPaint?) {
paint?.style = Paint.Style.STROKE
paint?.strokeJoin = Paint.Join.ROUND
paint?.strokeMiter = 10f
paint?.strokeWidth = 1f
}
}
当我尝试在JSX中使用此组件时,应用程序崩溃并显示给定错误:
Invariant Violation: Text strings must be rendered within a <Text> component