Skip to content

fix(Rating): Rating 评分组件 使用繁琐(#244) #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
33be1b2
编写选项卡组件
cuilanxin Aug 9, 2021
546167b
Merge branch 'uiwjs:master' into master
cuilanxin Aug 9, 2021
6745b07
类型名称请调整,添加组件文档在网站上展示
cuilanxin Aug 10, 2021
097c003
Merge branch 'uiwjs:master' into master
cuilanxin Aug 10, 2021
34c9512
Merge branch 'uiwjs:master' into master
cuilanxin Aug 10, 2021
ba7d98d
#162修复报错
cuilanxin Aug 10, 2021
8f8f636
fix:#162修复报错
cuilanxin Aug 10, 2021
014b41e
Merge branch 'uiwjs:master' into master
cuilanxin Aug 11, 2021
c527a46
Merge branch 'uiwjs:master' into master
cuilanxin Aug 12, 2021
d5e1868
Merge branch 'uiwjs:master' into master
cuilanxin Aug 13, 2021
7666f22
SpeedDial 悬浮标记
cuilanxin Aug 13, 2021
fabb11c
优化类型
cuilanxin Aug 14, 2021
2f50aee
优化类型
cuilanxin Aug 14, 2021
4caa341
feat: Tooltip组件
cuilanxin Aug 18, 2021
1b816b4
Merge branch 'uiwjs:master' into master
cuilanxin Aug 19, 2021
1b83b97
Merge branch 'uiwjs:master' into master
cuilanxin Aug 27, 2021
6298643
Merge branch 'uiwjs:master' into master
cuilanxin Sep 4, 2021
7060c03
feat(ActionSheet): Add new component.
cuilanxin Sep 5, 2021
504acae
Merge branch 'uiwjs:master' into master
cuilanxin Sep 6, 2021
6495f4a
fix: ActionSheet 实例优化,组件优化
cuilanxin Sep 6, 2021
b8763e8
Merge branch 'uiwjs:master' into master
cuilanxin Sep 7, 2021
e787fbf
Merge branch 'uiwjs:master' into master
cuilanxin Sep 8, 2021
e4aee47
feat(SearchInputBar): Add new component.
cuilanxin Sep 8, 2021
f4826f1
Merge branch 'uiwjs:master' into master
cuilanxin Sep 9, 2021
bf8c66d
feat(Pagination): Add new component.
cuilanxin Sep 9, 2021
24de46e
Merge branch 'uiwjs:master' into master
cuilanxin Sep 10, 2021
875e6c5
fix(Tooltip): 修复cloud弹出元素位置问题
cuilanxin Sep 10, 2021
6cf91d4
Merge branch 'uiwjs:master' into master
cuilanxin Sep 10, 2021
293e07c
Merge branch 'uiwjs:master' into master
cuilanxin Sep 14, 2021
a37c701
Merge branch 'uiwjs:master' into master
cuilanxin Sep 16, 2021
96181ef
Merge branch 'uiwjs:master' into master
cuilanxin Sep 17, 2021
858069e
doc(Drawer): Update README.md
cuilanxin Sep 18, 2021
11d115f
doc: Update README.md
cuilanxin Sep 19, 2021
880ab58
Merge branch 'uiwjs:master' into master
cuilanxin Sep 19, 2021
c9d297f
fix(Rating): Rating 评分组件 使用繁琐(#244)
cuilanxin Sep 20, 2021
b27d30e
fix(Rating): Rating 评分组件 使用繁琐(#244)
cuilanxin Sep 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions example/examples/src/routes/Rating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export default class Index extends Component<IndexProps, IndexState> {
<Body>
<View style={styles.divider} />
<Rating
defaultRating={5}
// count={10}
defaultRating={2}
resultRating={10}
icon={[<Icon name="star-off" />, <Icon name="star-on" />]}
// icon={["star-off", "star-on"]}
onPress={console.log}
/>
<View style={styles.divider} />
<Rating />
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/Drawer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Demo() {
```

## 注意事项 - 抽屉高度是页面有效高度

```jsx
import { Fragment } from 'react';
import { View, Text, SafeAreaView } from 'react-native';
Expand All @@ -77,7 +78,9 @@ function Demo() {
);
}
```

## 抽屉覆盖全屏

- 可查看 [react-native-root-siblings](https://www.npmjs.com/package/react-native-root-siblings) 文档
```jsx
// 在 App.js 文件中
Expand Down Expand Up @@ -123,6 +126,7 @@ function Demo() {
);
}
```

## props

| 参数 | 说明 | 类型 | 默认值 |
Expand Down
20 changes: 9 additions & 11 deletions packages/core/src/Rating/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ import { TabsItemIconTypes } from '@uiw/react-native'

export type icoType = [TabsItemIconTypes, TabsItemIconTypes]
export interface RatingProps {
/** 默认几个 */
defaultRating?: number,
/** 总分 */
count?: number,
/** 默认分数 */
defaultCount?: number,
/** 默认选中几个 */
defaultRating?: number;
/** 总数*/
resultRating?: number;
/** icon 大小 */
size?: number,
size?: number;
/** icon 颜色 */
color?: string,
color?: string;
/** [未选中, 已选中] */
icon?: icoType,
icon?: icoType;
/**
* void
* @param score type: number 得到几分
* @param score type: number 选中几个
*/
onPress?: (score: number) => void
onPress?: (score: number) => void;
}
```
73 changes: 29 additions & 44 deletions packages/core/src/Rating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { TabsItemIconTypes } from '../Tabs/TabsItem';

export type icoType = [TabsItemIconTypes, TabsItemIconTypes];
export interface RatingProps {
/** 默认几个 */
/** 默认选中几个 */
defaultRating?: number;
/** 总分 */
count?: number;
/** 默认分数 */
defaultCount?: number;
/** 总数*/
resultRating?: number;
/** icon 大小 */
size?: number;
/** icon 颜色 */
Expand All @@ -27,83 +25,70 @@ export interface RatingProps {

export interface RatingState {
icon: Array<IconsName | React.ReactElement | React.ReactNode>;
count: number;
defaultCount: number;
resultRating: number;
size: number;
color: string;
defaultRating: number;
typeIcon: icoType;
}

export default class Rating extends React.Component<RatingProps, RatingState> {
// static state: RatingState
constructor(props: RatingProps) {
super(props);
let start = (props.icon && props.icon[0]) || 'star-off';
let end = (props.icon && props.icon[1]) || 'star-on';
this.state = {
defaultRating: props.defaultRating || 5,
defaultRating: props.defaultRating || 0,
resultRating: props.resultRating || 5,
icon: [],
count: props.count ?? 5,
defaultCount: props.defaultCount ?? 1,
size: props.size ?? 24,
color: props.color || '#ebc445',
typeIcon: [start, end],
};
}
componentDidMount() {
const { defaultCount } = this.state;
this.updateIcon(defaultCount);
const { defaultRating } = this.state;
this.updateIcon(defaultRating);
}
flag = true;
updateIcon = (index: number) => {
const { defaultRating } = this.state;
const { resultRating } = this.state;
const { onPress } = this.props;
let start = this.state.typeIcon[0];
let end = this.state.typeIcon[1];
if (index === 1 && this.flag) {
this.setState({ icon: [...new Array(index).fill(end), ...new Array(defaultRating - index).fill(start)] });
this.setState({ icon: [...new Array(index).fill(end), ...new Array(resultRating - index).fill(start)] });
onPress?.(1);
this.flag = false;
} else if (index === 1 && !this.flag) {
this.setState({ icon: [...new Array(index - 1).fill(end), ...new Array(defaultRating - index + 1).fill(start)] });
this.setState({ icon: [...new Array(index - 1).fill(end), ...new Array(resultRating - index + 1).fill(start)] });
this.flag = true;
onPress?.(0);
} else {
this.setState({ icon: [...new Array(index).fill(end), ...new Array(defaultRating - index).fill(start)] });
this.setState({ icon: [...new Array(index).fill(end), ...new Array(resultRating - index).fill(start)] });
this.flag = true;
onPress?.(index);
}
};
render() {
return (
<View>
{/* <Text >{this.state.count}</Text> */}
<View style={styles.RatingContainer}>
{this.state.icon.map((item, index) => {
if (typeof item === 'string') {
return (
<TouchableOpacity
onPress={() => {
this.updateIcon(index + 1);
this.props.onPress &&
this.props.onPress((this.state.count / this.state.defaultRating) * (index + 1));
}}
key={index}
>
return (
<TouchableOpacity
onPress={() => {
this.updateIcon(index + 1);
}}
key={index}
>
{typeof item === 'string' ? (
<Icon name={item as IconsName} color="#ebc445" size={this.state.size} />
</TouchableOpacity>
);
} else {
return (
<TouchableOpacity
onPress={() => {
this.updateIcon(index + 1);
this.props.onPress &&
this.props.onPress((this.state.count / this.state.defaultRating) * (index + 1));
}}
key={index}
>
{item}
</TouchableOpacity>
);
}
) : (
item
)}
</TouchableOpacity>
);
})}
</View>
</View>
Expand Down