mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-05 22:56:11 +00:00
# Summary Due to the large number of example apps in the repository, I decided to change the structure and move all applications into an "apps" folder to maintain a clear structure.
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import React, {Fragment} from 'react';
|
|
import {ScrollView, Text, View} from 'react-native';
|
|
import {Examples, Sample} from './types';
|
|
|
|
export default function composeComponents(
|
|
components: Sample[] | Examples,
|
|
renderInView?: boolean,
|
|
) {
|
|
const Wrapper = renderInView ? View : ScrollView;
|
|
return function ComposedComponent() {
|
|
return (
|
|
<Wrapper
|
|
{...(renderInView
|
|
? {style: {alignItems: 'center'}}
|
|
: {
|
|
contentContainerStyle: {
|
|
alignItems: 'center',
|
|
paddingVertical: 25,
|
|
},
|
|
})}>
|
|
{Array.isArray(components)
|
|
? components.map((Component, index) => (
|
|
<Fragment key={index}>
|
|
<ComponentTitle title={Component.title} />
|
|
<Component />
|
|
{index !== components.length - 1 && <Separator />}
|
|
</Fragment>
|
|
))
|
|
: null}
|
|
</Wrapper>
|
|
);
|
|
};
|
|
}
|
|
|
|
function ComponentTitle({title}: {title?: string}) {
|
|
if (!title) return null;
|
|
return (
|
|
<Text
|
|
style={{
|
|
marginHorizontal: 20,
|
|
textAlign: 'center',
|
|
marginBottom: 5,
|
|
}}>
|
|
{title}
|
|
</Text>
|
|
);
|
|
}
|
|
|
|
function Separator() {
|
|
return (
|
|
<View
|
|
style={{
|
|
height: 1,
|
|
marginVertical: 24,
|
|
width: '100%',
|
|
backgroundColor: 'gray',
|
|
}}
|
|
/>
|
|
);
|
|
}
|