Skip to content

Commit ae188e0

Browse files
authored
TabController - remove from incubator and remove support for children in TabBar (#1182)
1 parent 86e7e00 commit ae188e0

File tree

15 files changed

+23
-1160
lines changed

15 files changed

+23
-1160
lines changed

demo/src/screens/componentScreens/TabBarScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class TabBarScreen extends Component {
151151

152152
<TabBar style={styles.tabbar} selectedIndex={0} ref={r => (this.tabbar = r)} enableShadow>
153153
<TabBar.Item label="Scroll"/>
154-
<TabBar.Item label="View" badge={{size: 6}}/>
154+
<TabBar.Item label="View" badgeProps={{size: 6}}/>
155155
<TabBar.Item label="tab"/>
156156
<TabBar.Item label="bar"/>
157157
<TabBar.Item label="Container"/>

demo/src/screens/componentScreens/TabControllerScreen/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TabControllerScreen extends Component<{}, State> {
4343

4444
const addItem: TabControllerItemProps = {icon: Assets.icons.demo.add, key: 'add', ignore: true, width: 60, onPress: this.onAddItem};
4545

46-
return [...items, addItem];
46+
return fewItems ? items : [...items, addItem];
4747
};
4848

4949
componentDidMount() {
@@ -154,9 +154,7 @@ class TabControllerScreen extends Component<{}, State> {
154154
enableShadow
155155
activeBackgroundColor={Colors.blue60}
156156
centerSelected={centerSelected}
157-
>
158-
{/* {this.renderTabItems()} */}
159-
</TabController.TabBar>
157+
/>
160158
{this.renderTabPages()}
161159
</TabController>
162160
<View absB left margin-20 marginB-100 style={{zIndex: 1}}>

generatedTypes/components/badge/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export declare type BadgeProps = ViewProps & TouchableOpacityProps & {
1515
/**
1616
* the badge size (default, small)
1717
*/
18-
size: number;
18+
size?: number;
1919
/**
2020
* Press handler
2121
*/
@@ -344,7 +344,7 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
344344
/**
345345
* the badge size (default, small)
346346
*/
347-
size: number;
347+
size?: number | undefined;
348348
/**
349349
* Press handler
350350
*/

generatedTypes/incubator/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export { default as TabController } from './TabController';
21
export { default as TextField } from './TextField';
32
export { default as TouchableOpacity, TouchableOpacityProps } from './TouchableOpacity';
43
export { default as WheelPicker } from './WheelPicker';

src/components/badge/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type BadgeProps = ViewProps &
3636
/**
3737
* the badge size (default, small)
3838
*/
39-
size: number;
39+
size?: number;
4040
/**
4141
* Press handler
4242
*/

src/components/tabController/TabBar.tsx

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjec
1111
import View from '../../components/view';
1212
import {Colors, Spacings, Typography} from '../../style';
1313
import {Constants} from '../../helpers';
14-
import {LogService} from '../../services';
1514
import FadedScrollView from './FadedScrollView';
1615

1716
import {useScrollToItem} from '../../hooks';
@@ -114,11 +113,7 @@ export interface TabControllerBarProps {
114113
testID?: string;
115114
}
116115

117-
type ChildProps = React.ReactElement<TabControllerItemProps>;
118-
119-
interface Props extends TabControllerBarProps, BaseComponentInjectedProps, ForwardRefInjectedProps {
120-
children?: ChildProps[] | ChildProps;
121-
}
116+
interface Props extends TabControllerBarProps, BaseComponentInjectedProps, ForwardRefInjectedProps {}
122117

123118
/**
124119
* @description: TabController's TabBar component
@@ -144,47 +139,27 @@ const TabBar = (props: Props) => {
144139
containerWidth: propsContainerWidth,
145140
centerSelected,
146141
containerStyle,
147-
testID,
148-
children: propsChildren
142+
testID
149143
} = props;
150144

151145
const context = useContext(TabBarContext);
152146
// @ts-ignore // TODO: typescript
153147
const {itemStates, items: contextItems, currentPage, targetPage, registerTabItems, selectedIndex} = context;
154148

155-
const children = useRef<Props['children']>(_.filter(propsChildren, (child: ChildProps) => !!child));
156-
157149
const _registerTabItems = () => {
158150
const ignoredItems: number[] = [];
159-
let itemsCount;
160-
161-
if (propsItems) {
162-
itemsCount = _.size(propsItems);
163-
_.forEach(propsItems, (item, index) => {
164-
if (item.ignore) {
165-
ignoredItems.push(index);
166-
}
167-
});
168-
// TODO: deprecate with props.children
169-
} else {
170-
itemsCount = React.Children.count(children.current);
171-
// @ts-ignore TODO: typescript - not sure if this can be solved
172-
React.Children.toArray(children.current).forEach((child: ChildProps, index: number) => {
173-
if (child.props.ignore) {
174-
ignoredItems.push(index);
175-
}
176-
});
177-
}
151+
const itemsCount = _.size(propsItems);
152+
_.forEach(propsItems, (item, index) => {
153+
if (item.ignore) {
154+
ignoredItems.push(index);
155+
}
156+
});
178157

179158
registerTabItems(itemsCount, ignoredItems);
180159
};
181160

182161
useEffect(() => {
183-
if (propsChildren) {
184-
LogService.warn('uilib: Please pass the "items" prop to TabController.TabBar instead of children');
185-
}
186-
187-
if ((propsItems || children.current) && !contextItems) {
162+
if (propsItems && !contextItems) {
188163
_registerTabItems();
189164
}
190165
}, []);
@@ -196,7 +171,7 @@ const TabBar = (props: Props) => {
196171
return contextItems || propsItems;
197172
}, [contextItems, propsItems]);
198173

199-
const itemsCount = useRef<number>(items ? _.size(items) : React.Children.count(children.current));
174+
const itemsCount = useRef<number>(_.size(items));
200175

201176
const {scrollViewRef: tabBar, onItemLayout, itemsWidths, focusIndex} = useScrollToItem({
202177
itemsCount: itemsCount.current,
@@ -216,7 +191,11 @@ const TabBar = (props: Props) => {
216191
return offsets;
217192
}, [itemsWidths]);
218193

219-
const _renderTabBarItems = useMemo((): ReactNode => {
194+
const renderTabBarItems = useMemo((): ReactNode => {
195+
if (_.isEmpty(itemStates)) {
196+
return null;
197+
}
198+
220199
return _.map(items, (item, index) => {
221200
return (
222201
<TabBarItem
@@ -239,6 +218,7 @@ const TabBar = (props: Props) => {
239218
);
240219
});
241220
}, [
221+
items,
242222
labelColor,
243223
selectedLabelColor,
244224
labelStyle,
@@ -252,46 +232,6 @@ const TabBar = (props: Props) => {
252232
onItemLayout
253233
]);
254234

255-
// TODO: Remove once props.children is deprecated
256-
const _renderTabBarItemsFromChildren = useMemo((): ReactNode | null => {
257-
return !children.current
258-
? null
259-
: React.Children.map(children.current, (child: Partial<ChildProps>, index: number) => {
260-
// @ts-ignore TODO: typescript - not sure if this can be easily solved
261-
return React.cloneElement(child, {
262-
labelColor,
263-
selectedLabelColor,
264-
labelStyle,
265-
selectedLabelStyle,
266-
uppercase,
267-
iconColor,
268-
selectedIconColor,
269-
activeBackgroundColor,
270-
...child.props,
271-
...context,
272-
index,
273-
state: itemStates[index],
274-
onLayout: centerSelected ? onItemLayout : undefined
275-
});
276-
});
277-
}, [
278-
labelColor,
279-
selectedLabelColor,
280-
labelStyle,
281-
selectedLabelStyle,
282-
uppercase,
283-
iconColor,
284-
selectedIconColor,
285-
activeBackgroundColor,
286-
itemStates,
287-
centerSelected,
288-
onItemLayout
289-
]);
290-
291-
const renderTabBarItems = useMemo(() => {
292-
return _.isEmpty(itemStates) ? null : items ? _renderTabBarItems : _renderTabBarItemsFromChildren;
293-
}, [itemStates, items, _renderTabBarItems, _renderTabBarItemsFromChildren]);
294-
295235
const _indicatorWidth = new Value(0); // TODO: typescript?
296236
const _indicatorOffset = new Value(0); // TODO: typescript?
297237

src/incubator/TabController/PageCarousel.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/incubator/TabController/ReanimatedObject.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)