-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from BouyguesTelecom/fix/tabs-native
init tabs native
- Loading branch information
Showing
16 changed files
with
310 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ComponentName } from '@/components/enumsComponentsName' | ||
import { TabsProps } from '@/components/tabs/TabsProps' | ||
import { TabsContext } from '@/components/tabs/context' | ||
import React from 'react' | ||
import { View } from 'react-native' | ||
|
||
/** | ||
* Tabs Component | ||
* @param children {ReactNode} Children for tabs | ||
* @param activeIndex {number} default active tab index | ||
* @param inverted {boolean} Inverted style | ||
*/ | ||
const Tabs = ({ children, activeIndex, inverted }: TabsProps) => { | ||
const [currentIndex, setCurrentIndex] = React.useState<number>(activeIndex || 0) | ||
const [isInverted, setIsInverted] = React.useState<boolean>(inverted || false) | ||
|
||
React.useEffect(() => { | ||
activeIndex !== undefined && setCurrentIndex(activeIndex) | ||
}, [activeIndex]) | ||
|
||
React.useEffect(() => { | ||
setIsInverted(inverted || false) | ||
}, [inverted]) | ||
|
||
return ( | ||
<TabsContext.Provider | ||
value={{ | ||
activeIndex: currentIndex, | ||
inverted: isInverted, | ||
setInverted: setIsInverted, | ||
setActiveIndex: setCurrentIndex, | ||
}} | ||
> | ||
<View>{children}</View> | ||
</TabsContext.Provider> | ||
) | ||
} | ||
|
||
Tabs.displayName = ComponentName.Tabs | ||
export default Tabs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/react/components/tabs/tab-list/TabList.native.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ComponentName } from '@/components/enumsComponentsName' | ||
import { TabsContext } from '@/components/tabs/context' | ||
import Tab from '@/components/tabs/tab-list/tab/Tab' | ||
import { TabListProps } from '@/components/tabs/tab-list/TabListProps' | ||
import { getColorStyle, TrilogyColor } from '@/objects' | ||
import React from 'react' | ||
import { ScrollView, StyleSheet } from 'react-native' | ||
|
||
/** | ||
* Tabs Nav Component | ||
* @param children {ReactChild} React Child Element | ||
* @param className | ||
* @param id | ||
* @param testId | ||
* @param align | ||
* @param others | ||
*/ | ||
const TabList = ({ children, ...others }: TabListProps) => { | ||
const { inverted } = React.useContext(TabsContext) | ||
|
||
const styles = React.useMemo( | ||
() => | ||
StyleSheet.create({ | ||
tabList: { | ||
flexDirection: 'row', | ||
overflow: 'visible', | ||
backgroundColor: inverted ? getColorStyle(TrilogyColor.MAIN) : undefined, | ||
}, | ||
}), | ||
[inverted], | ||
) | ||
|
||
return ( | ||
<ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.tabList} {...others}> | ||
{React.Children.map(children, (child, index) => { | ||
if (!React.isValidElement(child)) return false | ||
return <Tab {...child.props} index={index} /> | ||
})} | ||
</ScrollView> | ||
) | ||
} | ||
|
||
TabList.displayName = ComponentName.TabList | ||
export default TabList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/react/components/tabs/tab-list/tab/Tab.native.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { ComponentName } from '@/components/enumsComponentsName' | ||
import { Icon } from '@/components/icon' | ||
import { TabsContext } from '@/components/tabs/context' | ||
import { TabProps } from '@/components/tabs/tab-list/tab/TabProps' | ||
import { Text } from '@/components/text' | ||
import { getColorStyle, TrilogyColor } from '@/objects/facets/Color' | ||
import React from 'react' | ||
import { GestureResponderEvent, Linking, StyleSheet, TouchableOpacity, View } from 'react-native' | ||
|
||
/** | ||
* Tabs Item Component | ||
* @param active {boolean} active tab item | ||
* @param children {ReactChild} React Child Element | ||
* @param onClick onClick Event | ||
* @param iconName {IconNameValues | IconName} add icon name | ||
* @param disabled {boolean} disable tab item | ||
* @param label {string} Tab content | ||
* @param to {string} Link | ||
* @param href {string} Link | ||
*/ | ||
const Tab = ({ active, onClick, to, href, iconName, label, disabled, ...others }: TabProps) => { | ||
const { index, ...props } = others as any | ||
const { activeIndex, setActiveIndex, inverted } = React.useContext(TabsContext) | ||
const isActive = React.useMemo(() => activeIndex === index, [activeIndex, index]) | ||
|
||
const handleClick = React.useCallback( | ||
(e: GestureResponderEvent) => { | ||
if (!disabled) { | ||
if (onClick) onClick(e) | ||
if (!to && !href) setActiveIndex(index) | ||
if (to || href) Linking.openURL(to || href || '') | ||
} | ||
}, | ||
[disabled, onClick, index, setActiveIndex, to, href], | ||
) | ||
|
||
const styles = React.useMemo( | ||
() => | ||
StyleSheet.create({ | ||
tab: { | ||
paddingVertical: 4, | ||
paddingHorizontal: 12, | ||
borderBottomWidth: 2, | ||
borderBottomColor: isActive | ||
? getColorStyle(disabled ? TrilogyColor.DISABLED : inverted ? TrilogyColor.BACKGROUND : TrilogyColor.MAIN) | ||
: 'transparent', | ||
}, | ||
text: { | ||
textAlign: 'center', | ||
color: getColorStyle( | ||
disabled ? TrilogyColor.DISABLED : inverted ? TrilogyColor.BACKGROUND : TrilogyColor.MAIN, | ||
), | ||
}, | ||
}), | ||
[isActive, disabled, inverted], | ||
) | ||
|
||
React.useEffect(() => { | ||
if (active) setActiveIndex(index) | ||
}, [active, setActiveIndex, index]) | ||
|
||
return ( | ||
<TouchableOpacity activeOpacity={1} style={styles.tab} onPress={handleClick} {...props}> | ||
{iconName && ( | ||
<View style={{ alignSelf: 'center' }}> | ||
<Icon | ||
color={disabled ? TrilogyColor.DISABLED : inverted ? TrilogyColor.BACKGROUND : TrilogyColor.MAIN} | ||
size='small' | ||
name={iconName} | ||
/> | ||
</View> | ||
)} | ||
<Text style={styles.text}>{label && label}</Text> | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
Tab.displayName = ComponentName.Tab | ||
export default Tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/react/components/tabs/tab-panels/TabPanels.native.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ComponentName } from '@/components/enumsComponentsName' | ||
import { TabsContext } from '@/components/tabs/context' | ||
import TabPanel from '@/components/tabs/tab-panels/tab-panel' | ||
import { TabPanelsProps } from '@/components/tabs/tab-panels/TabPanelsProps' | ||
import { getColorStyle, TrilogyColor } from '@/objects' | ||
import React from 'react' | ||
import { StyleSheet, View } from 'react-native' | ||
|
||
/** | ||
* Tabs Nav Component | ||
* @param children {ReactChild} React Child Element | ||
* @param className | ||
* @param id | ||
* @param testId | ||
* @param others | ||
*/ | ||
const TabPanels = ({ children, ...others }: TabPanelsProps) => { | ||
const { inverted } = React.useContext(TabsContext) | ||
|
||
const styles = React.useMemo( | ||
() => | ||
StyleSheet.create({ | ||
tabPanels: { | ||
paddingVertical: 8, | ||
backgroundColor: inverted ? getColorStyle(TrilogyColor.MAIN) : undefined, | ||
}, | ||
}), | ||
[inverted], | ||
) | ||
|
||
return ( | ||
<View style={styles.tabPanels} {...others}> | ||
{React.Children.map(children, (child, index) => { | ||
if (!React.isValidElement(child)) return false | ||
return <TabPanel {...child.props} index={index} /> | ||
})} | ||
</View> | ||
) | ||
} | ||
|
||
TabPanels.displayName = ComponentName.TabPanels | ||
export default TabPanels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.