Skip to content

Commit d74f5a6

Browse files
authored
Infra/picker new file (#2030)
* Replace Picker index with new file * Fix error in NativePicker related to how we pass dialog props * Add relevant displayName to internal components * Fix Picker tests - move to render tests * Fix displayName of PickerDialog * Fix lint errors
1 parent 06fda2f commit d74f5a6

File tree

7 files changed

+27
-566
lines changed

7 files changed

+27
-566
lines changed

src/components/picker/NativePicker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import _ from 'lodash';
2-
import React from 'react';
3-
import {BaseComponent} from '../../commons';
2+
import React, {Component} from 'react';
43
import TextField from '../textField';
54
import PickerDialog from './PickerDialog';
65
import TouchableOpacity from '../touchableOpacity';
76
import {Colors} from '../../style';
87
import {WheelPicker} from '../../incubator';
98

10-
class NativePicker extends BaseComponent {
11-
static displayName = 'IGNORE';
9+
class NativePicker extends Component {
10+
static displayName = 'NativePicker';
11+
1212
state = {
1313
selectedValue: this.props.value,
1414
items: this.extractPickerItems(this.props),
@@ -87,7 +87,7 @@ class NativePicker extends BaseComponent {
8787
return (
8888
<PickerDialog
8989
height={this.PICKER_HEIGHT + this.MENU_HEIGHT}
90-
{...this.getThemeProps()}
90+
{...this.props}
9191
visible={showDialog}
9292
panDirection={null}
9393
onDismiss={this.onCancel}

src/components/picker/PickerDialog.android.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import React from 'react';
1+
import React, {Component} from 'react';
22
import {StyleSheet, Text as RNText} from 'react-native';
33
import PropTypes from 'prop-types';
44
import _ from 'lodash';
55

6-
import {BaseComponent} from '../../commons';
7-
import {extractComponentProps} from '../../commons/modifiers';
86
import Dialog from '../dialog';
97
import View from '../view';
108
import Text from '../text';
119
import {Colors, BorderRadiuses} from '../../style';
1210

13-
class PickerDialog extends BaseComponent {
14-
static displayName = 'IGNORE';
11+
class PickerDialog extends Component {
12+
static displayName = 'PickerDialog';
1513
static propTypes = {
1614
onDone: PropTypes.func,
1715
onCancel: PropTypes.func,
@@ -62,12 +60,10 @@ class PickerDialog extends BaseComponent {
6260
}
6361

6462

65-
render() {
66-
const dialogProps = extractComponentProps(Dialog, this.props);
67-
// TODO: should be taken from dialogProps but there's an issue with "babel-plugin-typescript-to-proptypes" plugin
68-
const {panDirection} = this.props;
63+
render() {
64+
const {panDirection, visible, pickerModalProps} = this.props;
6965
return (
70-
<Dialog {...dialogProps} height="50%" width="77%" panDirection={panDirection}>
66+
<Dialog {...pickerModalProps} visible={visible} height="50%" width="77%" panDirection={panDirection}>
7167
<View style={styles.dialog}>
7268
{this.renderHeader()}
7369
<View flex center paddingH-24>

src/components/picker/PickerDialog.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import React from 'react';
1+
import React, {Component} from 'react';
22
import {StyleSheet} from 'react-native';
33
import PropTypes from 'prop-types';
44
import _ from 'lodash';
55

6-
import {BaseComponent} from '../../commons';
7-
import {extractComponentProps} from '../../commons/modifiers';
86
import Dialog from '../dialog';
97
import View from '../view';
108
import Text from '../text';
119
import {Colors} from '../../style';
1210

13-
class PickerDialog extends BaseComponent {
14-
static displayName = 'IGNORE';
11+
class PickerDialog extends Component {
12+
static displayName = 'PickerDialog';
1513
static propTypes = {
1614
onDone: PropTypes.func,
1715
onCancel: PropTypes.func,
@@ -38,11 +36,10 @@ class PickerDialog extends BaseComponent {
3836

3937

4038
render() {
41-
const dialogProps = extractComponentProps(Dialog, this.props);
42-
// TODO: should be taken from dialogProps but there's an issue with "babel-plugin-typescript-to-proptypes" plugin
43-
const {panDirection} = this.props;
39+
const {panDirection, visible, height, pickerModalProps} = this.props;
40+
4441
return (
45-
<Dialog {...dialogProps} width="100%" bottom animationConfig={{duration: 300}} panDirection={panDirection}>
42+
<Dialog {...pickerModalProps} visible={visible} height={height} width="100%" bottom animationConfig={{duration: 300}} panDirection={panDirection}>
4643
<View flex bg-$backgroundDefault>
4744
{this.renderHeader()}
4845
<View centerV flex>

src/components/picker/__tests__/index.spec.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useState} from 'react';
22
import {fireEvent, render} from '@testing-library/react-native';
3-
import Picker, {Picker as _Picker} from '../index';
3+
import Picker from '../index';
44

55
const countries = [
66
{label: 'Israel', value: 'IL'},
@@ -13,15 +13,16 @@ const countries = [
1313
describe('Picker', () => {
1414
describe('getLabel', () => {
1515
it('should get label of a simple item', () => {
16-
let uut = new _Picker({value: countries[2]});
17-
expect(uut.getLabelValueText()).toEqual(countries[2].label);
18-
uut = new _Picker({value: countries[3]});
19-
expect(uut.getLabelValueText()).toEqual(countries[3].label);
20-
});
2116

17+
let renderTree = render(<TestCase value={countries[2]}/>);
18+
renderTree.getByDisplayValue(countries[2].label);
19+
renderTree = render(<TestCase value={countries[3]}/>);
20+
renderTree.getByDisplayValue(countries[3].label);
21+
});
22+
2223
it('should get label out of an array of items', () => {
23-
const uut = new _Picker({value: [countries[2], countries[4]]});
24-
expect(uut.getLabelValueText()).toEqual(`${countries[2].label}, ${countries[4].label}`);
24+
const renderTree = render(<TestCase value={[countries[2], countries[4]]}/>);
25+
renderTree.getByDisplayValue(`${countries[2].label}, ${countries[4].label}`);
2526
});
2627
});
2728

0 commit comments

Comments
 (0)