Skip to content

Typescript/tab controller move to typescript #1079

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 34 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
885f586
Move TabBarContext from js ro ts
M-i-k-e-l Dec 15, 2020
d12ccc4
Move TabPage from js to tsx
M-i-k-e-l Dec 15, 2020
0405166
TabPage - move to typescript (fix typescript)
M-i-k-e-l Dec 15, 2020
982d177
Move PageCarousel from js to tsx
M-i-k-e-l Dec 15, 2020
1249e2e
PageCarousel - move to typescript (fix typescript)
M-i-k-e-l Dec 15, 2020
e7c2464
Fix TabPage exception
M-i-k-e-l Dec 15, 2020
9836261
Delete ReanimatedObject
M-i-k-e-l Dec 15, 2020
0c2c3ea
Move TabBarItem from js to tsx
M-i-k-e-l Dec 15, 2020
0314f98
export TabPageProps
M-i-k-e-l Dec 15, 2020
3a2af83
TabPage - fix description
M-i-k-e-l Dec 15, 2020
1beb39c
Commit .d files
M-i-k-e-l Dec 15, 2020
b2199d3
TabBarItem - move to typescript (fix typescript)
M-i-k-e-l Dec 15, 2020
feac3cd
PageCarousel - move to typescript (fix typescript) - part 2
M-i-k-e-l Dec 15, 2020
c1d257c
Move TabBar from js to tsx
M-i-k-e-l Dec 15, 2020
1086511
Move ScrollBarGradient from js to tsx
M-i-k-e-l Dec 15, 2020
3fa5940
ScrollBarGradient add props and docs
M-i-k-e-l Dec 15, 2020
0929830
Commit .d file
M-i-k-e-l Dec 15, 2020
1e677af
TabBar - move to typescript (fix typescript)
M-i-k-e-l Dec 16, 2020
8239fdb
Move TabBarController from js to tsx
M-i-k-e-l Dec 16, 2020
59f7572
TabController - move to typescript (fix typescript)
M-i-k-e-l Dec 16, 2020
89def2a
Move TabControllerScreen to ts
M-i-k-e-l Dec 16, 2020
94c3c69
Fix screen and some errors
M-i-k-e-l Dec 16, 2020
17d0e0a
Fix PR comments
M-i-k-e-l Dec 16, 2020
4cbab00
Fix prop
M-i-k-e-l Dec 16, 2020
b747c91
Fix/tab controller transition (#1089)
ethanshar Dec 20, 2020
e6975e2
Merge branch 'master' into typescript/tab-controller-move-to-typescript
M-i-k-e-l Dec 20, 2020
2b493ee
Move TabBarController from index.tsx to TabBarController.tsx
M-i-k-e-l Dec 20, 2020
cd52f05
Create TabControllerProps namespace
M-i-k-e-l Dec 20, 2020
0d3cff5
Create TabControllerProps namespace (fix screen)
M-i-k-e-l Dec 20, 2020
ede0f36
Revert "Create TabControllerProps namespace (fix screen)"
M-i-k-e-l Dec 21, 2020
2feb180
Revert "Create TabControllerProps namespace"
M-i-k-e-l Dec 21, 2020
0178216
Revert "Move TabBarController from index.tsx to TabBarController.tsx"
M-i-k-e-l Dec 21, 2020
d16185d
Change interfaces names for TabController related classes
M-i-k-e-l Dec 21, 2020
7e37a8c
Merge branch 'master' into typescript/tab-controller-move-to-typescript
M-i-k-e-l Dec 21, 2020
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
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
import React, {Component} from 'react';
import {ActivityIndicator} from 'react-native';
import {
Assets,
TabController,
Colors,
View,
Text,
Button
} from 'react-native-ui-lib'; //eslint-disable-line
import {Assets, TabController, Colors, View, Text, Button, TabControllerItemProps} from 'react-native-ui-lib';
import {gestureHandlerRootHOC} from 'react-native-gesture-handler';
import _ from 'lodash';

import Tab1 from './tab1';
import Tab2 from './tab2';
import Tab3 from './tab3';

const TABS = [
'Home',
'Posts',
'Reviews',
'Videos',
'Photos',
'Events',
'About',
'Community',
'Groups',
'Offers'
];

class TabControllerScreen extends Component {
constructor(props) {
super(props);
const TABS = ['Home', 'Posts', 'Reviews', 'Videos', 'Photos', 'Events', 'About', 'Community', 'Groups', 'Offers'];

interface State {
asCarousel: boolean;
centerSelected: boolean;
fewItems: boolean;
selectedIndex: number;
key: string | number;
items: TabControllerItemProps[];
}

class TabControllerScreen extends Component<{}, State> {


constructor(props: {}) {
super(props);
this.state = {
asCarousel: true,
centerSelected: false,
fewItems: false,
selectedIndex: 0,
key: Date.now()
key: Date.now(),
items: []
};

const items = this.generateTabItems();
this.state.items = items;

this.state.items = this.generateTabItems();
}

generateTabItems = (fewItems = this.state.fewItems, centerSelected = this.state.centerSelected): TabControllerItemProps[] => {
let items: TabControllerItemProps[] = _.chain(TABS)
.take(fewItems ? 3 : TABS.length)
.map<TabControllerItemProps>(tab => ({label: tab, key: tab}))
.value();

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

if (!centerSelected) {
items = [...items, addItem];
}
return items;
};

componentDidMount() {
// this.slow();
}
Expand All @@ -61,19 +65,7 @@ class TabControllerScreen extends Component {

onAddItem = () => {
console.warn('Add Item');
}

generateTabItems = (fewItems = this.state.fewItems, centerSelected = this.state.centerSelected) => {
let items = _.chain(TABS)
.take(fewItems ? 3 : TABS.length)
.map((tab) => ({label: tab, key: tab}))
.value();

if (!centerSelected) {
items = [...items, {icon: Assets.icons.demo.add, key: 'add', ignore: true, width: 60, onPress: this.onAddItem}];
}
return items;
}
};

toggleItemsCount = () => {
const {fewItems} = this.state;
Expand All @@ -97,14 +89,14 @@ class TabControllerScreen extends Component {
});
};

onChangeIndex = (selectedIndex) => {
onChangeIndex = (selectedIndex: number) => {
this.setState({selectedIndex});
};

renderLoadingPage() {
return (
<View flex center>
<ActivityIndicator size="large"/>
<ActivityIndicator size="large" />
<Text text60L marginT-10>
Loading
</Text>
Expand All @@ -119,18 +111,13 @@ class TabControllerScreen extends Component {
return (
<Container {...containerProps}>
<TabController.TabPage index={0}>
<Tab1/>
<Tab1 />
</TabController.TabPage>
<TabController.TabPage index={1}>
<Tab2/>
<Tab2 />
</TabController.TabPage>
<TabController.TabPage
index={2}
lazy
lazyLoadTime={1500}
renderLoading={this.renderLoadingPage}
>
<Tab3/>
<TabController.TabPage index={2} lazy lazyLoadTime={1500} renderLoading={this.renderLoadingPage}>
<Tab3 />
</TabController.TabPage>

{_.map(_.takeRight(TABS, TABS.length - 3), (title, index) => {
Expand All @@ -147,14 +134,7 @@ class TabControllerScreen extends Component {
}

render() {
const {
key,
selectedIndex,
asCarousel,
centerSelected,
fewItems,
items
} = this.state;
const {key, selectedIndex, asCarousel, centerSelected, fewItems, items} = this.state;
return (
<View flex bg-grey70>
<TabController
Expand All @@ -166,7 +146,7 @@ class TabControllerScreen extends Component {
>
<TabController.TabBar
// items={items}
// key={key}
key={key}
// uppercase
// indicatorStyle={{backgroundColor: 'green', height: 3}}
// labelColor={'green'}
Expand All @@ -188,22 +168,22 @@ class TabControllerScreen extends Component {
bg-green30={fewItems}
label={fewItems ? 'Show Many Items' : 'Show Few Items'}
marginB-12
size="small"
size={Button.sizes.small}
onPress={this.toggleItemsCount}
/>
<Button
bg-grey20={!asCarousel}
bg-green30={asCarousel}
label={`Carousel : ${asCarousel ? 'ON' : 'OFF'}`}
marginB-12
size="small"
size={Button.sizes.small}
onPress={this.toggleCarouselMode}
/>
<Button
bg-grey20={!centerSelected}
bg-green30={centerSelected}
label={`centerSelected : ${centerSelected ? 'ON' : 'OFF'}`}
size="small"
size={Button.sizes.small}
onPress={this.toggleCenterSelected}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {Colors, View, Text, Image, Assets, Button} from 'react-native-ui-lib'; //eslint-disable-line
import {View, Text, Image, Assets, Button} from 'react-native-ui-lib';

class Tab1 extends Component {
state = {};
Expand All @@ -19,7 +19,14 @@ class Tab1 extends Component {
Home
</Text>
<View absR marginR-20>
<Button marginT-20 round style={{width: 50}} size="small" iconSource={Assets.icons.search} white/>
<Button
marginT-20
round
style={{width: 50}}
size={Button.sizes.small}
iconSource={Assets.icons.search}
white
/>
</View>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {Colors, View, Text, Image, Assets, Button} from 'react-native-ui-lib'; //eslint-disable-line
import {View, Text, Image} from 'react-native-ui-lib';

class Tab2 extends Component {
state = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {Component} from 'react';
import {ScrollView} from 'react-native';
import _ from 'lodash';
import {Card, Avatar, View, Text, Image, Assets, Button} from 'react-native-ui-lib'; //eslint-disable-line
import {Card, Avatar, View, Text} from 'react-native-ui-lib';

class Tab2 extends Component {
state = {
loading: true,
loading: true
};

componentDidMount() {
Expand Down Expand Up @@ -51,10 +51,12 @@ class Tab2 extends Component {
<Avatar
size={50}
source={{
uri: 'https://static.pexels.com/photos/60628/flower-garden-blue-sky-hokkaido-japan-60628.jpeg',
uri: 'https://static.pexels.com/photos/60628/flower-garden-blue-sky-hokkaido-japan-60628.jpeg'
}}
/>
<Text text40 marginL-20>{index}</Text>
<Text text40 marginL-20>
{index}
</Text>
</Card>
);
})}
Expand Down
42 changes: 42 additions & 0 deletions generatedTypes/components/scrollBar/ScrollBarGradient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types="react" />
import { ImageSourcePropType } from 'react-native';
export interface ScrollBarGradientProps {
/**
* Is the gradient visible
*/
visible?: boolean;
/**
* Should the gradient be on the left (reverse)
*/
left?: boolean;
/**
* The gradient's width (default is 76)
*/
gradientWidth?: number;
/**
* The gradient's height (default 100%)
*/
gradientHeight?: number;
/**
* The gradient's margins (default is 0)
*/
gradientMargins?: number;
/**
* The gradient's height (default 100%)
* @deprecated
*/
height?: number;
/**
* The gradient's color (default is white)
*/
gradientColor?: string;
/**
* Image source for the gradient (default is assets/gradientOverlay.png)
*/
gradientImage?: ImageSourcePropType;
}
declare const ScrollBarGradient: {
({ visible, left, gradientWidth, gradientHeight, gradientMargins, height, gradientColor, gradientImage }: ScrollBarGradientProps): JSX.Element;
displayName: string;
};
export default ScrollBarGradient;
20 changes: 20 additions & 0 deletions generatedTypes/components/tabController/PageCarousel.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { PureComponent } from 'react';
import _ from 'lodash';
import Animated from 'react-native-reanimated';
/**
* @description: TabController's Page Carousel
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.js
* @notes: You must pass `asCarousel` flag to TabController and render your TabPages inside a PageCarousel
*/
declare class PageCarousel extends PureComponent {
static displayName: string;
static contextType: React.Context<{}>;
carousel: React.RefObject<Animated.ScrollView>;
onScroll: (...args: any[]) => void;
componentDidMount(): void;
onTabChange: ([index]: readonly number[]) => void;
scrollToPage: (pageIndex: number) => void;
renderCodeBlock: (() => JSX.Element) & _.MemoizedFunction;
render(): JSX.Element;
}
export default PageCarousel;
Loading