import React, {FC, useMemo, memo, useCallback} from 'react'; import {Props} from './types'; import {Container} from './styles'; import Item from './Item'; import {LayoutType} from '../../models/Layout'; import {ItemLayout} from '../../models/Item'; const Layout: FC = ({ id, type = LayoutType.ITEM, items, layouts, flex = 1, color = 'transparent', spacing = 0, borderRadius = 0, style, index, parentType, overlay, reverseX, reverseY, onPressItem, renderItemChildren, visible, }) => { const itemInfo = useMemo( () => (items && id ? items[id] : undefined), [id, items], ); const handleRenderItemChildren = useCallback(() => { if (renderItemChildren) { const v = itemInfo?.video && typeof itemInfo?.video === 'object' ? itemInfo?.video?.uri : undefined; return renderItemChildren({ itemId: id, photo: itemInfo?.photo?.uri, video: v, childrenProps: itemInfo?.childrenProps, }); } }, [renderItemChildren, itemInfo, id]); if (type === LayoutType.ITEM) { return ( {handleRenderItemChildren()} ); } return ( {layouts && layouts.map((layout, i) => ( ))} ); }; export default memo(Layout);