Now I have a clear picture. The issue is a fundamental design limitation: TextInput uses a native HTML <input> element for editing, which can only display plain text. When the input has focus, the engine hides the canvas-rendered rich text and shows the native input element with the raw text value. When focus is lost, the native element is hidden and the canvas re-renders the text with rich text formatting.
这是 TextInput 的设计限制,没法解决。TextInput 在点击获取焦点后,底层会切换到浏览器原生的 <input> 元素来接收输入,而原生 input 只能显示纯文本,不支持富文本渲染。失去焦点后才会回到引擎的 Text 渲染,这时富文本格式才能正常显示。
如果你的场景是只需要显示富文本而不需要用户编辑它,可以用 Label 代替 TextInput,Label 支持 html/ubb 富文本渲染且不会有这个问题。
如果确实需要可编辑的富文本输入框,LayaAir 的 TextInput 组件不支持这个能力,需要自己实现——比如用一个 Label 做显示层,用隐藏的 TextInput 做输入层,在 blur 事件时把原始文本同步到 Label 显示。
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。