Skip to content

Instantly share code, notes, and snippets.

@Karthik-B-06
Created May 30, 2021 17:15
Show Gist options
  • Save Karthik-B-06/48fdaa7f9c6fdc6f621d8f870e0edf65 to your computer and use it in GitHub Desktop.
Save Karthik-B-06/48fdaa7f9c6fdc6f621d8f870e0edf65 to your computer and use it in GitHub Desktop.
import React from 'react';
import { GestureResponderEvent, Pressable, StyleSheet, Text, View, ViewProps } from 'react-native';
import { headingTextStyle } from 'src/styles/textStyles';
import { tailwind } from 'tailwind';
type PageHeaderProps = {
leftNode?: JSX.Element;
rightNode?: JSX.Element;
headerText?: string;
handleOnPressLeftNode?: (event: GestureResponderEvent) => void;
handleOnPressRightNode?: (event: GestureResponderEvent) => void;
rightContainerStyle?: ViewProps['style'] | null;
leftContainerStyle?: ViewProps['style'] | null;
};
const PageHeader: React.FC<PageHeaderProps> = ({
leftNode = null,
rightNode = null,
headerText = '',
handleOnPressLeftNode = null,
handleOnPressRightNode = null,
rightContainerStyle = null,
leftContainerStyle = null,
}) => {
return (
<View style={styles.pageHeaderContainer}>
<Pressable onPress={handleOnPressLeftNode} style={leftContainerStyle || styles.leftItem}>
{leftNode}
</Pressable>
<View style={styles.headerItem}>
<Text style={[headingTextStyle.FS17_SEMIBOLD, tailwind('text-center')]}>{headerText}</Text>
</View>
<Pressable onPress={handleOnPressRightNode} style={rightContainerStyle || styles.rightItem}>
{rightNode}
</Pressable>
</View>
);
};
const styles = StyleSheet.create({
pageHeaderContainer: tailwind(
'flex flex-row items-center justify-between border-b border-gray-200',
),
leftItem: tailwind('flex-1 pl-4 py-4'),
rightItem: tailwind('flex-1 pr-4 items-end py-4'),
headerItem: tailwind('flex-1 py-4'),
});
export default PageHeader;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment