diff --git a/packages/shared/src/template.ts b/packages/shared/src/template.ts index 2302178dfc90..8908b3feed0c 100644 --- a/packages/shared/src/template.ts +++ b/packages/shared/src/template.ts @@ -227,6 +227,8 @@ export class BaseTemplate { return str + `bind${value}="eh" ` } else if (attr === 'class') { return str + `class="{{i.${Shortcuts.Class}}}" ` + } else if (attr === 'style') { + return str + `style="{{i.${Shortcuts.Style}}}" ` } return str + `${attr}="{{i.${toCamelCase(attr)}}}" ` diff --git a/packages/taro-components-rn/src/components/Input/PropsType.tsx b/packages/taro-components-rn/src/components/Input/PropsType.tsx index b0d5f96f1c15..f43757f28501 100644 --- a/packages/taro-components-rn/src/components/Input/PropsType.tsx +++ b/packages/taro-components-rn/src/components/Input/PropsType.tsx @@ -34,6 +34,8 @@ export interface InputProps extends FormItemProps{ cursor?: number; selectionStart: number; selectionEnd: number; + placeholderStyle?: string; + placeholderTextColor?: string; onInput?: (evt: Event) => void; onChange?: (evt: Event) => void; onFocus?: (evt: Event) => void; diff --git a/packages/taro-components-rn/src/components/Input/index.tsx b/packages/taro-components-rn/src/components/Input/index.tsx index bfe099985c65..81c97bee01c8 100644 --- a/packages/taro-components-rn/src/components/Input/index.tsx +++ b/packages/taro-components-rn/src/components/Input/index.tsx @@ -33,7 +33,7 @@ import { TextInputContentSizeChangeEventData, KeyboardTypeOptions } from 'react-native' -import { noop, omit } from '../../utils' +import { noop, omit, parseStyles } from '../../utils' import { InputProps, InputState } from './PropsType' const keyboardTypeMap: { [key: string]: string } = { @@ -193,8 +193,8 @@ class _Input extends React.Component { _autoHeight, autoFocus, focus, + placeholderStyle, } = this.props - const keyboardType: KeyboardTypeOptions = keyboardTypeMap[type] as KeyboardTypeOptions const selection = (() => { @@ -210,30 +210,36 @@ class _Input extends React.Component { // fix: https://reactnative.dev/docs/textinput#multiline const textAlignVertical = _multiline ? 'top' : 'auto' + const placeholderTextColor = this.props.placeholderTextColor || parseStyles(placeholderStyle)?.color + + const props = omit(this.props, [ + 'style', + 'value', + 'type', + 'password', + 'placeholder', + 'disabled', + 'maxlength', + 'confirmType', + 'confirmHold', + 'cursor', + 'selectionStart', + 'selectionEnd', + 'onInput', + 'onFocus', + 'onBlur', + 'onKeyDown', + 'onConfirm', + '_multiline', + '_autoHeight', + '_onLineChange', + 'placeholderStyle', + 'placeholderTextColor', + ]) + return ( { textAlignVertical={textAlignVertical} onContentSizeChange={this.onContentSizeChange} underlineColorAndroid="rgba(0,0,0,0)" - style={[{ - padding: 0, - }, style, _multiline && _autoHeight && { height: Math.max(35, this.state.height) }]} + placeholderTextColor={placeholderTextColor} + style={[ + { + padding: 0 + }, + style, + _multiline && _autoHeight && { height: Math.max(35, this.state.height) } + ]} /> ) } diff --git a/packages/taro-components/types/Button.d.ts b/packages/taro-components/types/Button.d.ts index 4ac9af8b2b71..59e13da41863 100644 --- a/packages/taro-components/types/Button.d.ts +++ b/packages/taro-components/types/Button.d.ts @@ -168,19 +168,13 @@ interface ButtonProps extends StandardProps { */ onGetPhoneNumber?: CommonEventFunction - /** 获取头像信息 - * - * 生效时机:`open-type="chooseavatar"` - * @supported weapp - */ - onChooseAvatar?: CommonEventFunction - /** 获取用户实名 * * 生效时机:`open-type="getRealnameAuthInfo"` + * @deprecated * @supported weapp */ - onGetRealnameAuthInfo?: CommonEventFunction + onGetRealNameAuthInfo?: CommonEventFunction /** 当使用开放能力时,发生错误的回调 * @@ -201,7 +195,14 @@ interface ButtonProps extends StandardProps { * 生效时机:`open-type="launchApp"` * @supported weapp */ - onLaunchapp?: CommonEventFunction + onLaunchApp?: CommonEventFunction + + /** 获取用户头像回调 + * + * 生效时机:`open-type="chooseAvatar"` + * @supported weapp + */ + onChooseAvatar?: CommonEventFunction } declare namespace ButtonProps { @@ -233,7 +234,7 @@ declare namespace ButtonProps { /** open-type 的合法值 */ interface openTypeKeys { weapp: { - /** 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息 + /** 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从回调中获得具体信息 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html */ contact @@ -241,19 +242,17 @@ declare namespace ButtonProps { * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95 */ share - /** 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息 + /** 获取用户手机号,可以从回调中获取到用户信息 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html */ getPhoneNumber - /** 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息 - * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html - */ - chooseAvatar - /** 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 */ + /** 获取用户信息,可以从回调中获取到用户信息 */ getUserInfo - /** 用户实名信息授权,已经弃用 */ - getRealnameAuthInfo - /** 打开APP,可以通过app-parameter属性设定向APP传的参数 + /** 用户实名信息授权 + * @deprecated + */ + getRealNameAuthInfo + /** 打开APP,可以通过 app-parameter 属性设定向APP传的参数 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html */ launchApp @@ -261,6 +260,8 @@ declare namespace ButtonProps { openSetting /** 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容 */ feedback + /** 获取用户头像,可以从回调中获得具体信息 */ + chooseAvatar } /** 支付宝小程序专属的 open-type 合法值 * @see https://opendocs.alipay.com/mini/component/button @@ -372,13 +373,10 @@ declare namespace ButtonProps { encryptedData: string /** 加密算法的初始向量 */ iv: string - /** 动态令牌。可通过动态令牌换取用户手机号。使用方法详情 [phonenumber.getPhoneNumber](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html) 接口 */ - code:string - } - - interface onChooseAvatarEventDetail { - /* 获取用户头像的临时链接 */ - avatarUrl: string + /** 动态令牌。可通过动态令牌换取用户手机号。 + * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95 + */ + code?: string } interface onOpenSettingEventDetail { diff --git a/packages/taro-components/types/Input.d.ts b/packages/taro-components/types/Input.d.ts index 176996e96e28..53018bd511be 100644 --- a/packages/taro-components/types/Input.d.ts +++ b/packages/taro-components/types/Input.d.ts @@ -35,6 +35,10 @@ interface InputProps extends StandardProps, FormItemProps { */ placeholderClass?: string + /** 指定 placeholder 文字的颜色 + * @supported rn + */ + placeholderTextColor?: string /** 是否禁用 * @supported weapp, h5, rn */ @@ -233,25 +237,24 @@ declare namespace InputProps { * @example_react * ```tsx * class App extends Component { - * * render () { * return ( - * - * 可以自动聚焦的 input - * - * 控制最大输入长度的 input - * - * 数字输入的 input - * - * 密码输入的 input - * - * 带小数点的 input - * - * 身份证输入的 input - * - * 控制占位符颜色的 input - * - * + * + * 可以自动聚焦的 input + * + * 控制最大输入长度的 input + * + * 数字输入的 input + * + * 密码输入的 input + * + * 带小数点的 input + * + * 身份证输入的 input + * + * 控制占位符颜色的 input + * + * * ) * } * } diff --git a/packages/taro-components/types/KeyboardAccessory.d.ts b/packages/taro-components/types/KeyboardAccessory.d.ts index 00d4f99b3f26..4ca0747296d8 100644 --- a/packages/taro-components/types/KeyboardAccessory.d.ts +++ b/packages/taro-components/types/KeyboardAccessory.d.ts @@ -4,21 +4,33 @@ import { StandardProps } from './common' /** @ignore */ type KeyboardAccessoryProps = StandardProps -/** 设置 input / textarea 聚焦时键盘上方 cover-view / cover-image 工具栏视图 +/** 设置 Input / Textarea 聚焦时键盘上方 CoverView / CoverImage 工具栏视图。需要配置 Taro 插件 `@tarojs/plugin-platform-weapp` 的 `enablekeyboardAccessory` 参数为 `true` 后才能使用,请参考:[#9548](https://github.com/NervJS/taro/issues/9548#issuecomment-891682216)。 * * @classification forms * @supported weapp * @example + * ```js + * // config/index.js + * { + * // ... + * plugins: [ + * ['@tarojs/plugin-platform-weapp', { + * enablekeyboardAccessory: true + * }] + * ] + * } + * ``` + * * ```tsx * class App extends Component { * render () { * return ( - * + * * ) * } * } diff --git a/packages/taro-components/types/Picker.d.ts b/packages/taro-components/types/Picker.d.ts index 771d159fb393..640b51717c1a 100644 --- a/packages/taro-components/types/Picker.d.ts +++ b/packages/taro-components/types/Picker.d.ts @@ -350,7 +350,7 @@ declare namespace PickerRegionProps { * * * - * + * *