Skip to content

Feat/new wheel picker integration #1083

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 54 commits into from
Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a3c353e
Change prop name to match current picker
mendyEdri Dec 15, 2020
3addf5e
Fix Container type, when no panDirection set - fixing scrollable cont…
mendyEdri Dec 15, 2020
18361d4
Merge branch 'master' of github.com:wix/react-native-ui-lib
mendyEdri Dec 17, 2020
d0fc5a7
added logic to support the current WheelPicker api and behaviour, add…
mendyEdri Dec 17, 2020
416f7f0
Support integrating new WeelPicker
mendyEdri Dec 17, 2020
0f64d32
New WheelPicker integration
mendyEdri Dec 17, 2020
cf182bc
WIP - picker item needs to be created
mendyEdri Dec 17, 2020
59ea97d
Fix build issue by reorder methods
mendyEdri Dec 17, 2020
3026c2b
Using reanimated tests stub to fix failing tests
mendyEdri Dec 17, 2020
b6ed3db
Merge branch 'master' of github.com:wix/react-native-ui-lib
mendyEdri Dec 20, 2020
3f7f1e5
fix WheelPicker demo screen
mendyEdri Dec 21, 2020
e289672
align items in demo screen
mendyEdri Dec 21, 2020
ba507b1
showcase both options to manage WeelPicker style
mendyEdri Dec 21, 2020
bc505f7
Merge branch 'master' of github.com:wix/react-native-ui-lib
mendyEdri Dec 21, 2020
3c30f46
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Dec 21, 2020
6d14cd7
typescript
mendyEdri Dec 21, 2020
35deda4
Fix extra space on the bottom of the wheel, use onLayout for starting…
mendyEdri Dec 22, 2020
9f8e50f
replace native WheelPicker in android with our new WheelPicker
mendyEdri Dec 22, 2020
01c95ea
replaced Android's WheelPicker when useNativePicker - with our new W…
mendyEdri Dec 23, 2020
25cb8b2
support WheelPicker to be fully controlled
mendyEdri Dec 23, 2020
714571f
added WheelPicker presenter
mendyEdri Dec 24, 2020
55528d1
implement WheelPicker presenter
mendyEdri Dec 24, 2020
b7894f3
WheelPicker unittests
mendyEdri Dec 24, 2020
3041c69
lint fix
mendyEdri Dec 24, 2020
5dda43c
ts file
mendyEdri Dec 24, 2020
ae3eb14
Merge branch 'master' into feat/new-wheel-picker-integration
ethanshar Dec 28, 2020
3e7eb77
fix android import
mendyEdri Dec 28, 2020
0303fbe
Merge branch 'feat/new-wheel-picker-integration' of github.com:wix/re…
mendyEdri Dec 28, 2020
312da06
wheel-picker import style
mendyEdri Dec 28, 2020
1ce4958
Fixing demo screen
mendyEdri Dec 29, 2020
139b30b
ts fix
mendyEdri Dec 29, 2020
d44a820
PR Comments - naming
mendyEdri Dec 29, 2020
e6deee1
Demo screen structure code
mendyEdri Dec 29, 2020
2cb3f07
PR Comment - spacing
mendyEdri Dec 29, 2020
2c3f0ef
Avoid check when offset send is -1 (prior render)
mendyEdri Dec 29, 2020
796c3e2
API naming
mendyEdri Dec 29, 2020
0174030
API naming + demo fixes
mendyEdri Dec 29, 2020
03e6eb9
PR Comments - added component memo, remove unnecessary memo from sepa…
mendyEdri Dec 29, 2020
0a06813
Style is based on parent, so no need for extra
mendyEdri Dec 29, 2020
0759a9d
Merge branch 'master' of github.com:wix/react-native-ui-lib
mendyEdri Dec 30, 2020
f8dfd17
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Dec 30, 2020
b56821c
fix lint errors
mendyEdri Dec 30, 2020
b045a30
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 3, 2021
5052368
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 5, 2021
8832dce
Merge branch 'master' into feat/new-wheel-picker-integration
ethanshar Jan 6, 2021
1b6235f
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 7, 2021
5dca309
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 19, 2021
e0e4ac2
merge master
mendyEdri Jan 19, 2021
5cd4107
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 27, 2021
418c9f7
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Jan 27, 2021
cce289d
Fixing issue when not passing back the onChange event
mendyEdri Mar 3, 2021
c460bb2
lint
mendyEdri Mar 3, 2021
0742539
Merge branch 'master' into feat/new-wheel-picker-integration
mendyEdri Mar 3, 2021
b45f0db
Merge branch 'master' into feat/new-wheel-picker-integration
ethanshar Mar 9, 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
57 changes: 45 additions & 12 deletions demo/src/screens/incubatorScreens/WheelPickerScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback} from 'react';
import React, {useCallback, useState} from 'react';
import {View, Text, Incubator, Colors, Typography} from 'react-native-ui-lib';
import _ from 'lodash';
import {ItemProps} from 'src/incubator/WheelPicker/Item';

// Months
const months = [
Expand All @@ -22,27 +21,61 @@ const months = [
// Years
const years = _.times(2020, i => i);

export default () => {
const useData = (initialMonth?: string, initialYear?: string) => {

const [selectedMonth, setMonth] = useState<string | undefined>(initialMonth);
const [selectedYear, setYear] = useState<string | undefined>(initialYear);

const onMonthChange = (item: string | undefined, _: number) => {
setMonth(item);
};

const onYearChange = (item: string | undefined, _: number) => {
setYear(item);
};

const getMonths = useCallback(() => {
return _.map(months, item => ({label: item, value: item}));
}, []);

const onChange = useCallback((index: number, item?: ItemProps) => {
console.log(item, index);
const getYears = useCallback(() => {
return _.map(years, item => ({label: '' + item, value: item}));
}, []);

return {
getMonths,
getYears,
onMonthChange,
onYearChange,
selectedMonth,
selectedYear
};
};

export default () => {

const {selectedMonth, onMonthChange, getMonths, selectedYear, onYearChange, getYears} = useData('February', undefined);

return (
<View flex padding-page>
<Text h1>Wheel Picker</Text>
<View flex centerV centerH paddingT-page>

<View flex centerV centerH>
<Text h3>Months</Text>
<Incubator.WheelPicker
onChange={onChange}
style={{width: '100%'}}
onChange={onMonthChange}
activeTextColor={Colors.primary}
inactiveTextColor={Colors.grey20}
items={_.map(months, i => ({text: i, value: i}))}
textStyle={{...Typography.text60R}}
items={getMonths()}
textStyle={Typography.text60R}
selectedValue={selectedMonth}
/>

<Text h3 marginT-s5>Years</Text>
<Incubator.WheelPicker onChange={onChange} items={_.map(years, i => ({text: '' + i, value: i}))} />

<Text h3>Years</Text>
<View height={300} width={'100%'}>
<Incubator.WheelPicker onChange={onYearChange} selectedValue={selectedYear} items={getYears()}/>
</View>
</View>
</View>
);
Expand Down
4 changes: 2 additions & 2 deletions generatedTypes/incubator/WheelPicker/Item.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="react" />
import { TextStyle } from 'react-native';
export interface ItemProps {
text: string;
label: string;
value: string | number;
}
interface InternalProps extends ItemProps {
Expand All @@ -13,5 +13,5 @@ interface InternalProps extends ItemProps {
style?: TextStyle;
onSelect: (index: number) => void;
}
declare const _default: ({ index, text, itemHeight, onSelect, offset, activeColor, inactiveColor, style }: InternalProps) => JSX.Element;
declare const _default: ({ index, label, itemHeight, onSelect, offset, activeColor, inactiveColor, style }: InternalProps) => JSX.Element;
export default _default;
79 changes: 52 additions & 27 deletions generatedTypes/incubator/WheelPicker/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
/// <reference types="react" />
import { TextStyle } from 'react-native';
import { ItemProps } from './Item';
import {TextStyle} from 'react-native';
import {ItemProps} from './Item';
export interface WheelPickerProps {
/**
* Data source for WheelPicker
*/
items?: ItemProps[];
/**
* Describe the height of each item in the WheelPicker
*/
itemHeight?: number;
/**
* Text color for the focused row
*/
activeTextColor?: string;
/**
* Text color for other, non-focused rows
*/
inactiveTextColor?: string;
/**
* Row text style
*/
textStyle?: TextStyle;
/**
* Event, on active row change
*/
onChange: (index: number, item?: ItemProps) => void;
/**
* Data source for WheelPicker
*/
items?: ItemProps[];
/**
* Describe the height of each item in the WheelPicker
* default value: 44
*/
itemHeight?: number;
/**
* Describe the number of rows visible
* default value: 5
*/
numberOfVisibleRows?: number;
/**
* Text color for the focused row
*/
activeTextColor?: string;
/**
* Text color for other, non-focused rows
*/
inactiveTextColor?: string;
/**
* Row text style
*/
textStyle?: TextStyle;
/**
* Event, on active row change
*/
onChange?: (item: string | undefined, index: number) => void;
/**
* Container's ViewStyle, height is computed according to itemHeight * numberOfVisibleRows
*/
style?: Omit<ViewStyle, 'height'>;
/**
* Support passing items as children props
*/
children?: JSX.Element | JSX.Element[];
/**
* WheelPicker initial value, can be ItemProps.value, number as index
*/
selectedValue?: ItemProps | string | number;
}
declare const WheelPicker: ({ items, itemHeight, activeTextColor, inactiveTextColor, textStyle, onChange: onChangeEvent }: WheelPickerProps) => JSX.Element;
declare const WheelPicker: ({
items,
itemHeight,
activeTextColor,
inactiveTextColor,
textStyle,
onChange: onChangeEvent
}: WheelPickerProps) => JSX.Element;
export default WheelPicker;
24 changes: 24 additions & 0 deletions generatedTypes/incubator/WheelPicker/usePresenter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="react" />
import { ItemProps } from './Item';
declare type ItemValueTypes = ItemProps | number | string;
export { ItemValueTypes };
declare type PropTypes = {
selectedValue: ItemValueTypes;
children?: JSX.Element | JSX.Element[];
items?: ItemProps[];
itemHeight: number;
preferredNumVisibleRows: number;
};
declare type RowItem = {
value: string | number;
index: number;
};
interface Presenter {
items: ItemProps[];
shouldControlComponent: (offset: number) => boolean;
index: number;
height: number;
getRowItemAtOffset: (offset: number) => RowItem;
}
declare const usePresenter: ({ selectedValue, children, items: propItems, itemHeight, preferredNumVisibleRows }: PropTypes) => Presenter;
export default usePresenter;
2 changes: 1 addition & 1 deletion jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ jest.spyOn(AccessibilityInfo, 'isScreenReaderEnabled').mockImplementation(() =>
// mock native modules
jest.mock('@react-native-community/blur', () => {});
jest.mock('@react-native-community/netinfo', () => {});
jest.mock('react-native-reanimated', () => ({}));
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
jest.mock('react-native-gesture-handler', () => {});
jest.mock('@react-native-picker/picker', () => ({Picker: {Item: {}}}));
12 changes: 10 additions & 2 deletions src/components/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,18 @@ class Dialog extends Component<DialogProps, DialogState> {
}
};

getContainerType = () => {
const {panDirection, renderPannableHeader} = this.props;
if (!panDirection || renderPannableHeader) {
return View;
}
return PanListenerView;
}

renderDialogView = () => {
const {children, renderPannableHeader, panDirection = PanningProvider.Directions.DOWN, containerStyle, testID} = this.props;
const {children, panDirection = PanningProvider.Directions.DOWN, containerStyle, testID} = this.props;
const {dialogVisibility} = this.state;
const Container = renderPannableHeader ? View : PanListenerView;
const Container = this.getContainerType();

return (
<View testID={testID} style={[this.styles.dialogViewSize]} pointerEvents="box-none">
Expand Down
10 changes: 8 additions & 2 deletions src/components/picker/NativePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import _ from 'lodash';
import React from 'react';
import {BaseComponent} from '../../commons';
import TextField from '../textField';
import {WheelPicker} from '../../nativeComponents';
import PickerDialog from './PickerDialog';
import TouchableOpacity from '../touchableOpacity';
import {Colors} from '../../style';
import {WheelPicker} from '../../nativeComponents';

class NativePicker extends BaseComponent {
static displayName = 'IGNORE';
Expand All @@ -15,6 +15,11 @@ class NativePicker extends BaseComponent {
showDialog: false
};

NUMBER_OF_ROWS = 5;
ROW_HEIGHT = 44;
MENU_HEIGHT = 44;
PICKER_HEIGHT = this.NUMBER_OF_ROWS * this.ROW_HEIGHT + this.MENU_HEIGHT;

extractPickerItems(props) {
const {children, useNativePicker} = props;
if (useNativePicker) {
Expand Down Expand Up @@ -59,9 +64,10 @@ class NativePicker extends BaseComponent {

renderPickerDialog = () => {
const {selectedValue, showDialog} = this.state;

return (
<PickerDialog
height={this.PICKER_HEIGHT + this.MENU_HEIGHT}
{...this.getThemeProps()}
visible={showDialog}
panDirection={null}
Expand Down
4 changes: 2 additions & 2 deletions src/components/picker/PickerDialog.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
import {Colors, BorderRadiuses} from '../../style';
import {WheelPicker} from '../../nativeComponents';
import {WheelPicker} from '../../incubator';

class PickerDialog extends BaseComponent {
static displayName = 'IGNORE';
Expand Down Expand Up @@ -74,7 +74,7 @@ class PickerDialog extends BaseComponent {
return renderNativePicker(this.props);
}
return (
<WheelPicker onValueChange={onValueChange} selectedValue={selectedValue} {...wheelPickerProps}>
<WheelPicker selectedValue={selectedValue} onChange={onValueChange} {...wheelPickerProps}>
{children}
</WheelPicker>
);
Expand Down
9 changes: 5 additions & 4 deletions src/components/picker/PickerDialog.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
import {Colors} from '../../style';
import {WheelPicker} from '../../nativeComponents';
import {WheelPicker} from '../../incubator';

class PickerDialog extends BaseComponent {
static displayName = 'IGNORE';
Expand Down Expand Up @@ -40,12 +40,12 @@ class PickerDialog extends BaseComponent {
}

renderPicker() {
const {children, onValueChange, selectedValue, renderNativePicker} = this.props;
const {children, onValueChange, selectedValue, renderNativePicker, pickerStyle} = this.props;
if (_.isFunction(renderNativePicker)) {
return renderNativePicker(this.props);
}
return (
<WheelPicker onValueChange={onValueChange} selectedValue={selectedValue}>
<WheelPicker style={pickerStyle} selectedValue={selectedValue} onChange={onValueChange}>
{children}
</WheelPicker>
);
Expand All @@ -56,12 +56,13 @@ class PickerDialog extends BaseComponent {
// TODO: should be taken from dialogProps but there's an issue with "babel-plugin-typescript-to-proptypes" plugin
const {panDirection} = this.props;
return (
<Dialog {...dialogProps} height={250} width="100%" migrate bottom animationConfig={{duration: 300}} panDirection={panDirection}>
<Dialog {...dialogProps} width="100%" migrate bottom animationConfig={{duration: 300}} panDirection={panDirection}>
<View flex bg-white>
{this.renderHeader()}
<View centerV flex>
{this.renderPicker()}
</View>
<View useSafeArea/>
</View>
</Dialog>
);
Expand Down
6 changes: 3 additions & 3 deletions src/incubator/WheelPicker/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AnimatedTouchableOpacity = Animated.createAnimatedComponent(
const AnimatedText = Animated.createAnimatedComponent(Text);

export interface ItemProps {
text: string;
label: string;
value: string | number;
}

Expand All @@ -27,7 +27,7 @@ interface InternalProps extends ItemProps {

export default ({
index,
text,
label,
itemHeight,
onSelect,
offset,
Expand Down Expand Up @@ -62,7 +62,7 @@ export default ({
index={index}
>
<AnimatedText text60R style={{color, ...style}}>
{text}
{label}
</AnimatedText>
</AnimatedTouchableOpacity>
);
Expand Down
Loading