You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中实现Otp输入框按填充状态切换边框颜色的技术问询

React Native OTP输入框边框动态变色实现

需求:OTP输入框填充内容时边框为白色,为空时边框为灰色。

当前实现代码如下:

组件逻辑代码

const otpFilled = !input
  ? styles.underlineStyleBase
  : styles.underlineStyleHighLighted;

<OtpInputs
  numberOfInputs={pinCount}
  defaultValue={input}
  handleChange={handleTextChange}
  inputStyles={styles.input}
  keyboardType="phone-pad"
  keyboardAppearance="dark"
  inputContainerStyles={[styles.underlineStyleBase, otpFilled]}
  focusStyles={styles.underlineStyleHighLighted}
  secureTextEntry={secureText}
  autofillFromClipboard={false}
  autoFocus={true}
  selectionColor={colors.brand_white}
  onBlur={handleOnBlur}
/>

样式代码

underlineStyleBase: {
  borderRadius: 12,
  height: 48,
  width: 48,
  borderColor: grey,
  borderWidth: 1,
  justifyContent: 'center',
  alignItems: 'center',
},
underlineStyleHighLighted: {
  borderColor: 'white',
},

内容的提问来源于stack exchange,提问作者Kumar Shivam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 19:10:32