@janiscommerce/ui-native
Version:
components library for Janis app
32 lines (31 loc) • 1.15 kB
JavaScript
import React from 'react';
import SwipeUp from '../../atoms/SwipeUp';
import Button from '../Button';
import { SwipeUpScrollView } from '../../atoms/SwipeUp/childComponents';
import { StyleSheet, View } from 'react-native';
import { verticalScale } from '../../../scale';
const styles = StyleSheet.create({
footerContainer: {
padding: verticalScale(17),
},
});
const SwipeList = React.forwardRef(({ renderHeader = () => { }, actions = [], children, ...props }, ref) => {
if (!children) {
return null;
}
const isRenderHeaderValid = typeof renderHeader === 'function';
const areThereValidActions = Array.isArray(actions) && actions.length > 0;
const renderActions = () => {
if (!areThereValidActions) {
return null;
}
return (<View style={styles.footerContainer}>
{actions?.map((action, idx) => (<Button key={idx} {...action}/>))}
</View>);
};
return (<SwipeUp ref={ref} footerComponent={renderActions} {...props}>
{isRenderHeaderValid && renderHeader()}
<SwipeUpScrollView>{children}</SwipeUpScrollView>
</SwipeUp>);
});
export default SwipeList;