-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add AvatarHeader components - add useStickyHeaderScrollProps used to handle snap-effect props - add usePredefinedHeader used to handle header props
- Loading branch information
1 parent
72b2155
commit 0410cc6
Showing
26 changed files
with
1,374 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
example/src/screens/additionalExamples/AvatarHeaderFlatListExample.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,48 @@ | ||
import { useNavigation } from '@react-navigation/native'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { StyleSheet, useColorScheme } from 'react-native'; | ||
|
||
// TODO: Change path when removing old API | ||
import { AvatarHeaderFlatList } from '../../../../src/predefinedComponents/AvatarHeader/AvatarHeaderFlatList'; | ||
import { Brandon } from '../../assets/data/cards'; | ||
import QuizCard from '../../components/QuizCard/QuizCard'; | ||
|
||
export const AvatarHeaderFlatListExample: FC = () => { | ||
const navigation = useNavigation(); | ||
|
||
function goBack() { | ||
navigation.goBack(); | ||
} | ||
|
||
const isDarkTheme = useColorScheme() === 'dark'; | ||
|
||
return <AvatarHeaderFlatList | ||
leftTopIcon={require('../../assets/icons/iconCloseWhite.png')} | ||
leftTopIconOnPress={goBack} | ||
rightTopIcon={require('../../assets/icons/Icon-Menu.png')} | ||
contentContainerStyle={[ styles.content, isDarkTheme ? styles.darkBackground : styles.lightBackground ]} | ||
backgroundColor={Brandon.color} | ||
hasBorderRadius | ||
image={Brandon.image} | ||
subtitle={Brandon.about} | ||
title={Brandon.author} | ||
data={Brandon.cards} | ||
keyExtractor={(item) => item.question} | ||
renderItem={({ item, index }) => <QuizCard data={item} num={index} cardsAmount={Brandon.cards.length} />} | ||
/>; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
content: { | ||
alignItems: 'center', | ||
alignSelf: 'stretch', | ||
paddingHorizontal: 24, | ||
}, | ||
darkBackground: { | ||
backgroundColor: 'black', | ||
}, | ||
lightBackground: { | ||
backgroundColor: 'white', | ||
}, | ||
}); |
51 changes: 51 additions & 0 deletions
51
example/src/screens/additionalExamples/AvatarHeaderScrollViewExample.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,51 @@ | ||
import { useNavigation } from '@react-navigation/native'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { StyleSheet, View, useColorScheme } from 'react-native'; | ||
|
||
// TODO: Change path when removing old API | ||
import { AvatarHeaderScrollView } from '../../../../src/predefinedComponents/AvatarHeader/AvatarHeaderScrollView'; | ||
import { Brandon } from '../../assets/data/cards'; | ||
import QuizCard from '../../components/QuizCard/QuizCard'; | ||
|
||
export const AvatarHeaderScrollViewExample: FC = () => { | ||
const navigation = useNavigation(); | ||
|
||
function goBack() { | ||
navigation.goBack(); | ||
} | ||
|
||
const isDarkTheme = useColorScheme() === 'dark'; | ||
|
||
return <AvatarHeaderScrollView | ||
leftTopIcon={require('../../assets/icons/iconCloseWhite.png')} | ||
leftTopIconOnPress={goBack} | ||
rightTopIcon={require('../../assets/icons/Icon-Menu.png')} | ||
contentContainerStyle={[ isDarkTheme ? styles.darkBackground : styles.lightBackground ]} | ||
backgroundColor={Brandon.color} | ||
hasBorderRadius | ||
image={Brandon.image} | ||
subtitle={Brandon.about} | ||
title={Brandon.author} | ||
> | ||
<View style={styles.content}> | ||
{Brandon.cards.map((data, i, arr) => | ||
<QuizCard data={data} num={i} key={data.question} cardsAmount={arr.length} /> | ||
)} | ||
</View> | ||
</AvatarHeaderScrollView>; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
content: { | ||
alignItems: 'center', | ||
flex: 1, | ||
paddingHorizontal: 24, | ||
}, | ||
darkBackground: { | ||
backgroundColor: 'black', | ||
}, | ||
lightBackground: { | ||
backgroundColor: 'white', | ||
}, | ||
}); |
64 changes: 64 additions & 0 deletions
64
example/src/screens/additionalExamples/AvatarHeaderSectionListExample.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,64 @@ | ||
import { useNavigation } from '@react-navigation/native'; | ||
import type { FC } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import type { SectionListData } from 'react-native'; | ||
import { StyleSheet, useColorScheme } from 'react-native'; | ||
|
||
// TODO: Change path when removing old API | ||
import { AvatarHeaderSectionList } from '../../../../src/predefinedComponents/AvatarHeader/AvatarHeaderSectionList'; | ||
import { Brandon } from '../../assets/data/cards'; | ||
import QuizCard from '../../components/QuizCard/QuizCard'; | ||
import { SectionFooter } from '../../components/primitiveComponents/SectionFooter'; | ||
import { SectionHeader } from '../../components/primitiveComponents/SectionHeader'; | ||
|
||
export const AvatarHeaderSectionListExample: FC = () => { | ||
const navigation = useNavigation(); | ||
|
||
function goBack() { | ||
navigation.goBack(); | ||
} | ||
|
||
const isDarkTheme = useColorScheme() === 'dark'; | ||
|
||
const sections = useMemo(() => { | ||
const section: SectionListData<typeof Brandon.cards[0]> = { | ||
data: Brandon.cards, | ||
keyExtractor: (item) => item.question, | ||
renderItem: ({ item, index }) => <QuizCard data={item} num={index} cardsAmount={Brandon.cards.length} />, | ||
}; | ||
|
||
return [ section, section, section ]; | ||
}, []); | ||
|
||
return <AvatarHeaderSectionList | ||
leftTopIcon={require('../../assets/icons/iconCloseWhite.png')} | ||
leftTopIconOnPress={goBack} | ||
rightTopIcon={require('../../assets/icons/Icon-Menu.png')} | ||
contentContainerStyle={[ styles.content, isDarkTheme ? styles.darkBackground : styles.lightBackground ]} | ||
backgroundColor={Brandon.color} | ||
hasBorderRadius | ||
image={Brandon.image} | ||
subtitle={Brandon.about} | ||
title={Brandon.author} | ||
renderSectionHeader={() => { | ||
return <SectionHeader />; | ||
}} | ||
renderSectionFooter={() => { | ||
return <SectionFooter />; | ||
}} | ||
sections={sections} | ||
/>; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
content: { | ||
alignSelf: 'stretch', | ||
paddingHorizontal: 24, | ||
}, | ||
darkBackground: { | ||
backgroundColor: 'black', | ||
}, | ||
lightBackground: { | ||
backgroundColor: 'white', | ||
}, | ||
}); |
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
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,15 @@ | ||
import { useWindowDimensions } from 'react-native'; | ||
|
||
export function useResponsiveSize() { | ||
const { height, width } = useWindowDimensions(); | ||
|
||
function responsiveHeight(value: number) { | ||
return height * (value / 100); | ||
} | ||
|
||
function responsiveWidth(value: number) { | ||
return width * (value / 100); | ||
} | ||
|
||
return { responsiveHeight, responsiveWidth }; | ||
} |
98 changes: 98 additions & 0 deletions
98
src/predefinedComponents/AvatarHeader/AvatarHeaderFlatList.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,98 @@ | ||
import type { ForwardedRef, ReactElement, RefAttributes } from 'react'; | ||
import React, { forwardRef, useImperativeHandle } from 'react'; | ||
import type { FlatList } from 'react-native'; | ||
import { View } from 'react-native'; | ||
|
||
import commonStyles from '../../constants/screenStyles'; | ||
import { StickyHeaderFlatList } from '../../primitiveComponents/StickyHeaderFlatList'; | ||
import type { AvatarHeaderFlatListProps } from './AvatarHeaderProps'; | ||
import { HeaderBar } from './components/HeaderBar'; | ||
import { useAvatarHeader } from './useAvatarHeader'; | ||
|
||
function AvatarHeaderFlatListInner<ItemT>( | ||
props: AvatarHeaderFlatListProps<ItemT>, | ||
ref: ForwardedRef<FlatList<ItemT>> | ||
) { | ||
const { | ||
backgroundColor, | ||
contentContainerStyle, | ||
data, | ||
decelerationRate = 'fast', | ||
keyExtractor, | ||
leftTopIcon, | ||
leftTopIconAccessibilityLabel, | ||
leftTopIconOnPress, | ||
leftTopIconTestID, | ||
nestedScrollEnabled = true, | ||
overScrollMode = 'never', | ||
renderHeaderBar, | ||
renderItem, | ||
rightTopIcon, | ||
rightTopIconAccessibilityLabel, | ||
rightTopIconOnPress, | ||
rightTopIconTestID, | ||
scrollEventThrottle = 16, | ||
title, | ||
...rest | ||
} = props; | ||
const { | ||
onMomentumScrollEnd, | ||
onScroll, | ||
onScrollEndDrag, | ||
parallaxHeight, | ||
renderHeader, | ||
scrollValue, | ||
scrollViewRef, | ||
} = useAvatarHeader<FlatList<ItemT>>(props); | ||
|
||
useImperativeHandle(ref, () => scrollViewRef.current as FlatList<ItemT>); | ||
|
||
return ( | ||
<View style={[commonStyles.wrapper, { backgroundColor }]}> | ||
{renderHeaderBar ? ( | ||
renderHeaderBar() | ||
) : ( | ||
<HeaderBar | ||
backgroundColor={backgroundColor} | ||
height={parallaxHeight} | ||
leftTopIcon={leftTopIcon} | ||
leftTopIconAccessibilityLabel={leftTopIconAccessibilityLabel} | ||
leftTopIconOnPress={leftTopIconOnPress} | ||
leftTopIconTestID={leftTopIconTestID} | ||
rightTopIcon={rightTopIcon} | ||
rightTopIconAccessibilityLabel={rightTopIconAccessibilityLabel} | ||
rightTopIconOnPress={rightTopIconOnPress} | ||
rightTopIconTestID={rightTopIconTestID} | ||
scrollValue={scrollValue} | ||
title={title} | ||
/> | ||
)} | ||
<View style={commonStyles.wrapper}> | ||
<StickyHeaderFlatList | ||
ref={scrollViewRef} | ||
{...rest} | ||
contentContainerStyle={contentContainerStyle} | ||
data={data} | ||
decelerationRate={decelerationRate} | ||
keyExtractor={keyExtractor} | ||
nestedScrollEnabled={nestedScrollEnabled} | ||
onMomentumScrollEnd={onMomentumScrollEnd} | ||
onScrollEndDrag={onScrollEndDrag} | ||
onScroll={onScroll} | ||
overScrollMode={overScrollMode} | ||
renderHeader={renderHeader} | ||
renderItem={renderItem} | ||
scrollEventThrottle={scrollEventThrottle} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
type AvatarHeaderFlatListType = <ItemT>( | ||
props: AvatarHeaderFlatListProps<ItemT> & RefAttributes<FlatList<ItemT>> | ||
) => ReactElement; | ||
|
||
export const AvatarHeaderFlatList = forwardRef( | ||
AvatarHeaderFlatListInner | ||
) as AvatarHeaderFlatListType; |
28 changes: 28 additions & 0 deletions
28
src/predefinedComponents/AvatarHeader/AvatarHeaderProps.ts
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,28 @@ | ||
import type { ColorValue, ImageSourcePropType } from 'react-native'; | ||
|
||
import type { | ||
StickyHeaderFlatListProps, | ||
StickyHeaderScrollViewProps, | ||
StickyHeaderSectionListProps, | ||
} from '../../primitiveComponents/StickyHeaderProps'; | ||
import type { IconProps, SharedPredefinedProps } from '../common/SharedProps'; | ||
|
||
export interface AvatarHeaderSharedProps extends IconProps, SharedPredefinedProps { | ||
hasBorderRadius?: boolean; | ||
image?: ImageSourcePropType; | ||
subtitle?: string; | ||
tabsContainerBackgroundColor?: ColorValue; | ||
title?: string; | ||
} | ||
|
||
export interface AvatarHeaderScrollViewProps | ||
extends AvatarHeaderSharedProps, | ||
StickyHeaderScrollViewProps {} | ||
|
||
export interface AvatarHeaderFlatListProps<ItemT> | ||
extends AvatarHeaderSharedProps, | ||
StickyHeaderFlatListProps<ItemT> {} | ||
|
||
export interface AvatarHeaderSectionListProps<ItemT, SectionT> | ||
extends AvatarHeaderSharedProps, | ||
StickyHeaderSectionListProps<ItemT, SectionT> {} |
Oops, something went wrong.