Skip to content

Commit e6e766d

Browse files
committed
fix(SearchBar): 增加placeholderColor api & 继承SearchInputBar属性
1 parent 4465faa commit e6e766d

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

example/examples/src/routes/SearchBar/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState} from 'react';
2-
import {SafeAreaView} from 'react-native';
2+
import {SafeAreaView, Text} from 'react-native';
33
import {SearchBar} from '@uiw/react-native';
44
import {ComProps} from '../../routes';
55
import Layout from '../../Layout';
@@ -40,6 +40,9 @@ const SearchBarDemo = (props: ComProps) => {
4040
labelInValue
4141
options={data}
4242
onChange={val => console.log('val', val)}
43+
placeholderColor="#333"
44+
placeholder="请输入"
45+
searchRender={<Text>请搜索111</Text>}
4346
/>
4447
</SafeAreaView>
4548
);

packages/core/src/SearchBar/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,63 @@ export default Demo
128128

129129
```
130130

131+
### 修改搜索文本默认颜色
132+
133+
```jsx mdx:preview&background=#bebebe29
134+
import { SearchBar } from '@uiw/react-native';
135+
import React from 'react';
136+
137+
function Demo() {
138+
return (
139+
<SearchBar
140+
showClear
141+
labelInValue
142+
options={[
143+
{label:'上海',value:1},
144+
{label:'南京',value:2}
145+
]}
146+
onFocus={()=>{}}
147+
onChange={val=>console.log('val',val)}
148+
placeholder="请输入搜索"
149+
placeholderColor="red"
150+
/>
151+
);
152+
}
153+
154+
export default Demo
155+
156+
```
157+
158+
### 继承了 SearchInputBar的属性
159+
160+
```jsx mdx:preview&background=#bebebe29
161+
import { SearchBar } from '@uiw/react-native';
162+
import { Text } from 'react-native';
163+
import React from 'react';
164+
165+
function Demo() {
166+
return (
167+
<SearchBar
168+
showClear
169+
labelInValue
170+
options={[
171+
{label:'上海',value:1},
172+
{label:'南京',value:2}
173+
]}
174+
onFocus={()=>{}}
175+
onChange={val=>console.log('val',val)}
176+
placeholder="请输入搜索"
177+
searchRender={<Text>自定义搜索</Text>}
178+
/>
179+
);
180+
}
181+
182+
export default Demo
183+
184+
```
185+
131186
### Props
187+
集成继承 `SearchInputBar` 属性
132188

133189
| 参数 | 说明 | 类型 | 默认值 |
134190
|------|------|-----|------|
@@ -144,6 +200,8 @@ export default Demo
144200
| extra | 图标 | JSX.Element | - |
145201
| showClear | 是否展示清除图标 | boolean | - |
146202
| contentStyle | 容器样式 | StyleProp<`ViewStyle`> | - |
203+
| placeholderColor | 搜索框默认文本颜色 | ColorValue | - |
204+
147205

148206

149207
### OptionsStateProps

packages/core/src/SearchBar/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, memo, useCallback } from 'react';
1+
import React, { useState, useEffect, memo } from 'react';
22
import {
33
View,
44
Text,
@@ -9,14 +9,14 @@ import {
99
Pressable,
1010
StyleProp,
1111
ViewStyle,
12+
ColorValue,
1213
} from 'react-native';
1314
import MaskLayer from '../MaskLayer';
14-
import SearchInputBar from '../SearchInputBar';
15+
import SearchInputBar, { SearchInputBarProps } from '../SearchInputBar';
1516
import List from '../List';
16-
import { down } from './svg';
1717
import Icon from '../Icon';
1818

19-
interface SearchBarProps {
19+
interface SearchBarProps extends Omit<SearchInputBarProps, 'onChange' | 'value'> {
2020
onChangeText?: (value: string) => void;
2121
options?: Array<OptionsState>;
2222
onChange?: (value: string | null) => void;
@@ -30,6 +30,7 @@ interface SearchBarProps {
3030
extra?: JSX.Element;
3131
showClear?: boolean;
3232
contentStyle?: StyleProp<ViewStyle>;
33+
placeholderColor?: ColorValue;
3334
}
3435

3536
interface OptionsState {
@@ -52,6 +53,8 @@ function SearchBar({
5253
extra,
5354
showClear = true,
5455
contentStyle = {},
56+
placeholderColor,
57+
...searchInputBarProps
5558
}: SearchBarProps) {
5659
const [curValue, setCurValue] = useState<any>(value);
5760
const [visible, setVisivble] = useState(false);
@@ -83,7 +86,7 @@ function SearchBar({
8386
return !visible ? (
8487
<Pressable onPress={showSearchBar}>
8588
<View style={[disabled ? styles.disabled : styles.content, contentStyle]}>
86-
<Text style={styles.contentTitle}>{textValue ? textValue : placeholder}</Text>
89+
<Text style={[styles.contentTitle, { color: placeholderColor }]}>{textValue ? textValue : placeholder}</Text>
8790
{React.isValidElement(extra) ? (
8891
extra
8992
) : curValue && showClear ? (
@@ -124,6 +127,7 @@ function SearchBar({
124127
</View>
125128
</TouchableWithoutFeedback>
126129
}
130+
{...searchInputBarProps}
127131
/>
128132
{loading ? (
129133
<ActivityIndicator color="#0A0258" size="large" style={styles.loading} />

0 commit comments

Comments
 (0)