Skip to content
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

feat: Tag supports long press #24

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions components/tag/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface TagPropsType {
onChange?: (selected: boolean) => void;
onClose?: () => void;
afterClose?: () => void;
onLongPress?: () => void;
}
7 changes: 7 additions & 0 deletions components/tag/__tests__/index.test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ describe('Tag', () => {
expect(afterClose).toHaveBeenCalled();
expect(wrapper.find('TouchableWithoutFeedback')).toHaveLength(0);
});

it('onLongPress then callback', () => {
const onLongPress = jest.fn();
const wrapper = shallow(<Tag onLongPress={onLongPress}>Basic</Tag>);
wrapper.find('TouchableWithoutFeedback').at(0).simulate('longPress');
expect(onLongPress).toHaveBeenCalledWith();
});
});
8 changes: 8 additions & 0 deletions components/tag/demo/basic.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export default class BasicTagExample extends React.Component<any, any> {
</Tag>
<WhiteSpace />
<Tag small>Small and Readonly</Tag>
<WhiteSpace />
<Tag
onLongPress={() => {
console.log('onLongPress');
}}
>
LongPress
</Tag>
</View>
);
}
Expand Down
1 change: 1 addition & 0 deletions components/tag/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Properties | Descrition | Type | Default
| onChange | The callback function that is triggered when the selected state changes. | (selected: bool): void | - |
| onClose | The callback function that is triggered when the tag is closed. | (): void | - |
| afterClose | The callback function that is triggered after close. | (): void | - |
| onLongPress | The callback function that is triggered when the tag is long pressed. | (): void | - |
13 changes: 12 additions & 1 deletion components/tag/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class Tag extends React.Component<TagNativeProps, any> {
onClose() {},
afterClose() {},
onChange() {},
onLongPress() {},
styles: TagStyles,
};

Expand Down Expand Up @@ -68,6 +69,16 @@ export default class Tag extends React.Component<TagNativeProps, any> {
);
}

handleLongPress = () => {
const { disabled, onLongPress } = this.props;
if (disabled) {
return;
}
if (onLongPress) {
onLongPress();
}
}

onTagClose = () => {
if (this.props.onClose) {
this.props.onClose();
Expand Down Expand Up @@ -158,7 +169,7 @@ export default class Tag extends React.Component<TagNativeProps, any> {

return !this.state.closed ? (
<View style={[styles.tag, style]}>
<TouchableWithoutFeedback onPress={this.onClick}>
<TouchableWithoutFeedback onPress={this.onClick} onLongPress={this.handleLongPress}>
<View style={[styles.wrap, sizeWrapStyle, wrapStyle]}>
<Text style={[styles.text, sizeTextStyle, textStyle]}>
{children}{' '}
Expand Down
1 change: 1 addition & 0 deletions components/tag/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ subtitle: 标签
| onChange | 切换选中回调函数 | (selected: bool): void | 无 |
| onClose | 点关闭时的回调函数 | (): void | 无 |
| afterClose | 关闭后的回调 | (): void | 无 |
| onLongPress | 长按的回调 | (): void | 无 |