import React, {useState} from 'react';
import {StyleSheet, ScrollView} from 'react-native';
import {
View,
Text,
Button,
Colors,
SegmentedControl,
ScreenFooter,
ScreenFooterLayouts,
ScreenFooterBackgrounds,
KeyboardBehavior,
FooterAlignment,
HorizontalItemsDistribution,
ItemsFit,
Switch,
TextField,
Hooks,
Incubator,
Icon
} from 'react-native-ui-lib';
import {SafeAreaContextPackage} from '../../optionalDependencies';
const SafeAreaProvider = SafeAreaContextPackage?.SafeAreaProvider;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const basketIcon = require('../../assets/icons/collections.png');
enum ButtonType {
PRIMARY = 'Primary',
SECONDARY = 'Secondary',
LINK = 'Link'
}
enum ItemSize {
SMALL = 'small',
MEDIUM = 'medium',
LARGE = 'large'
}
const ITEMS_COUNT_OPTIONS = [
{label: '1', value: 1},
{label: '2', value: 2},
{label: '3', value: 3}
];
const LAYOUT_OPTIONS = [
{label: 'Horizontal', value: ScreenFooterLayouts.HORIZONTAL},
{label: 'Vertical', value: ScreenFooterLayouts.VERTICAL}
];
const BACKGROUND_OPTIONS = [
{label: 'Solid', value: ScreenFooterBackgrounds.SOLID},
{label: 'Fading', value: ScreenFooterBackgrounds.FADING},
{label: 'Transparent', value: ScreenFooterBackgrounds.TRANSPARENT}
];
const ALIGNMENT_OPTIONS = [
{label: 'Start', value: FooterAlignment.START},
{label: 'Center', value: FooterAlignment.CENTER},
{label: 'End', value: FooterAlignment.END}
];
const DISTRIBUTION_OPTIONS = [
{label: 'Stack', value: HorizontalItemsDistribution.STACK},
{label: 'Spread', value: HorizontalItemsDistribution.SPREAD}
];
const ITEMS_FIT_OPTIONS = [
{label: 'Fit', value: ItemsFit.FIT},
{label: 'Stretch', value: ItemsFit.STRETCH},
{label: 'Fixed', value: ItemsFit.FIXED}
];
const BUTTON_TYPE_OPTIONS = [
{label: 'Primary', value: ButtonType.PRIMARY},
{label: 'Secondary', value: ButtonType.SECONDARY},
{label: 'Link', value: ButtonType.LINK}
];
const SIZE_OPTIONS = [
{label: 'Small', value: ItemSize.SMALL},
{label: 'Medium', value: ItemSize.MEDIUM},
{label: 'Large', value: ItemSize.LARGE}
];
const KEYBOARD_BEHAVIOR_OPTIONS = [
{label: 'Sticky', value: KeyboardBehavior.STICKY},
{label: 'Hoisted', value: KeyboardBehavior.HOISTED}
];
const KEYBOARD_BEHAVIOR_OPTIONS_SPACED = [
{label: 'Sticky', value: KeyboardBehavior.STICKY},
{label: 'Hoisted', value: KeyboardBehavior.HOISTED},
{label: '', value: 'dummy'}
];
const MissingDependencyScreen = () => {
return (
Missing Dependency
This screen requires react-native-safe-area-context to be installed.
Run: npm/yarn install react-native-safe-area-context
);
};
const ScreenFooterContent = () => {
const [itemsCount, setItemsCount] = useState(2);
const [layout, setLayout] = useState(ScreenFooterLayouts.HORIZONTAL);
const [background, setBackground] = useState(ScreenFooterBackgrounds.SOLID);
const [keyboardBehavior, setKeyboardBehavior] = useState(KeyboardBehavior.STICKY);
const [alignment, setAlignment] = useState(FooterAlignment.CENTER);
const [horizontalAlignment, setHorizontalAlignment] = useState(FooterAlignment.CENTER);
const [distribution, setDistribution] = useState(HorizontalItemsDistribution.STACK);
const [itemsFit, setItemsFit] = useState(ItemsFit.FIT);
const [button1Type, setButton1Type] = useState(ButtonType.PRIMARY);
const [button2Type, setButton2Type] = useState(ButtonType.SECONDARY);
const [button3Type, setButton3Type] = useState(ButtonType.LINK);
const [buttonSize, setButtonSize] = useState(ItemSize.MEDIUM);
const [showExtraText, setShowExtraText] = useState(false);
const [showImage, setShowImage] = useState(false);
const [extraContentSize, setExtraContentSize] = useState(ItemSize.MEDIUM);
const [useLongButtonText, setUseLongButtonText] = useState(false);
const [itemWidth, setItemWidth] = useState(150);
const [shouldHideOnScroll, setShouldHideOnScroll] = useState(false);
const {onScroll, visible} = Hooks.useScrollToHide();
const isHorizontal = layout === ScreenFooterLayouts.HORIZONTAL;
const getButtonSize = (size: ItemSize) => {
switch (size) {
case ItemSize.SMALL:
return Button.sizes.small;
case ItemSize.MEDIUM:
return Button.sizes.medium;
case ItemSize.LARGE:
return Button.sizes.large;
}
};
const getTextPreset = (size: ItemSize): {main: string; subtext: string} => {
switch (size) {
case ItemSize.SMALL:
return {main: 'text80', subtext: 'text100'};
case ItemSize.MEDIUM:
return {main: 'text70', subtext: 'text90'};
case ItemSize.LARGE:
return {main: 'text60', subtext: 'text80'};
}
};
const getButtonProps = (type: ButtonType) => {
switch (type) {
case ButtonType.PRIMARY:
return {
backgroundColor: Colors.$backgroundPrimaryHeavy,
label: useLongButtonText ? 'Primary-longtxtlongtxtlongtxtlongtxtlongtxtlongtxt' : 'Checkout'
};
case ButtonType.SECONDARY:
return {
backgroundColor: Colors.$backgroundDefault,
outline: true,
outlineColor: Colors.$backgroundPrimaryHeavy,
label: 'Secondary'
};
case ButtonType.LINK:
return {
link: true,
backgroundColor: undefined,
label: 'Link',
color: Colors.$backgroundPrimaryHeavy
};
}
};
const getImageSize = (size: ItemSize): number => {
switch (size) {
case ItemSize.SMALL:
return 24;
case ItemSize.MEDIUM:
return 32;
case ItemSize.LARGE:
return 40;
}
};
const renderFooterItems = () => {
const items = [];
const textPreset = getTextPreset(extraContentSize);
const imageSize = getImageSize(extraContentSize);
// Extra Text (Total price)
if (showExtraText) {
items.push(
Total:{' '}
257$
Including VAT.
);
}
// Image (Basket icon)
if (showExtraText && showImage) {
items.push(
);
}
if (itemsCount >= 1) {
items.push();
}
if (itemsCount >= 2) {
items.push();
}
if (itemsCount >= 3) {
items.push();
}
return items;
};
return (
ScreenFooter Configuration
{/* Hide On Scroll Toggle */}
Hide on Scroll
{/* Layout Selection */}
Layout
opt.value === layout)}
onChangeIndex={index => setLayout(LAYOUT_OPTIONS[index].value)}
/>
{/* Items Count */}
Number of Items
opt.value === itemsCount)}
onChangeIndex={index => setItemsCount(ITEMS_COUNT_OPTIONS[index].value)}
/>
{/* Extra Text Toggle */}
Show Extra Text
{/* Show Image Toggle (only when Extra Text is shown) */}
{showExtraText && (
Show Image
)}
{/* Extra Content Size */}
{showExtraText && (
Extra Content Size
opt.value === extraContentSize)}
onChangeIndex={index => setExtraContentSize(SIZE_OPTIONS[index].value)}
/>
)}
{/* Button Size (applies to all buttons) */}
Button Size
opt.value === buttonSize)}
onChangeIndex={index => setButtonSize(SIZE_OPTIONS[index].value)}
/>
{/* Long Button Text Toggle */}
Use Long Button Text
{/* Button 1 Type */}
{itemsCount >= 1 && (
Button 1 Type
opt.value === button1Type)}
onChangeIndex={index => setButton1Type(BUTTON_TYPE_OPTIONS[index].value)}
/>
)}
{/* Button 2 Type */}
{itemsCount >= 2 && (
Button 2 Type
opt.value === button2Type)}
onChangeIndex={index => setButton2Type(BUTTON_TYPE_OPTIONS[index].value)}
/>
)}
{/* Button 3 Type */}
{itemsCount >= 3 && (
Button 3 Type
opt.value === button3Type)}
onChangeIndex={index => setButton3Type(BUTTON_TYPE_OPTIONS[index].value)}
/>
)}
{/* Background */}
Background
opt.value === background)}
onChangeIndex={index => setBackground(BACKGROUND_OPTIONS[index].value)}
/>
{/* Position */}
Keyboard Behavior
opt.value === keyboardBehavior)}
onChangeIndex={index => setKeyboardBehavior(KEYBOARD_BEHAVIOR_OPTIONS[index].value)}
/>
{/* Alignment (Cross Axis) */}
{isHorizontal ? 'Vertical Alignment' : 'Alignment'}
opt.value === alignment)}
onChangeIndex={index => setAlignment(ALIGNMENT_OPTIONS[index].value)}
/>
{/* Distribution (for Horizontal layout) */}
{isHorizontal && (
Distribution
opt.value === distribution)}
onChangeIndex={index => setDistribution(DISTRIBUTION_OPTIONS[index].value)}
/>
)}
{/* Horizontal Alignment (for Horizontal layout + Stack distribution) */}
{isHorizontal && distribution === HorizontalItemsDistribution.STACK && (
Horizontal Alignment
opt.value === horizontalAlignment)}
onChangeIndex={index => setHorizontalAlignment(ALIGNMENT_OPTIONS[index].value)}
/>
)}
{/* Items Fit */}
Items Fit
opt.value === itemsFit)}
onChangeIndex={index => setItemsFit(ITEMS_FIT_OPTIONS[index].value)}
/>
{/* Item Width Slider (only when Fixed is selected) */}
{itemsFit === ItemsFit.FIXED && (
Item Width: {itemWidth}px
)}
{/* Spacer for content */}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.
{renderFooterItems()}
);
};
const ScreenFooterScreen = () => {
if (!SafeAreaProvider) {
return ;
}
return ;
};
const styles = StyleSheet.create({
scrollContent: {
padding: 20,
paddingBottom: 150
},
rowContainer: {
flexDirection: 'row'
}
});
export default ScreenFooterScreen;