Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content showing above the header part #411

Open
devWaleed opened this issue Jul 29, 2021 · 1 comment
Open

Content showing above the header part #411

devWaleed opened this issue Jul 29, 2021 · 1 comment

Comments

@devWaleed
Copy link

devWaleed commented Jul 29, 2021

Screenshot_20210729-200510_MyApp

Content is showing above header. Here is my code in functional component:


const SECTIONS = [
	{
		title: 'First Header',
		content: 'First content text',
	},
	{
		title: 'Second Header',
		content: 'Second content text',
	},
];

export default function Step1() {
	const [activeSections, setActiveSections] = useState([]);

	const _renderSectionTitle = (section) => {
		return (
			<View style={styles.content}>
				<Text>{section.content}</Text>
			</View>
		);
	};

	const _renderHeader = (section) => {
		return (
			<View style={styles.header}>
				<Text style={styles.headerText}>{section.title}</Text>
			</View>
		);
	};

	const _renderContent = (section) => {
		return (
			<View style={styles.content}>
				<Text>{section.content}</Text>
			</View>
		);
	};

	const _updateSections = (activeSections) => {
		console.log('activeSections', activeSections);
		setActiveSections(activeSections);
	};

	return (
		<View style={{ paddingVertical: 25, paddingHorizontal: 20 }}>
			<Text style={{ fontFamily: Fonts.paragraph }}>This is some text above accordian</Text>

			<Accordion
				sections={SECTIONS}
				activeSections={activeSections}
				renderSectionTitle={_renderSectionTitle}
				renderHeader={_renderHeader}
				renderContent={_renderContent}
				onChange={_updateSections}
				renderAsFlatList={false}
			/>

			<Text style={{ fontFamily: Fonts.paragraph }}>This is some text below accordian</Text>
		</View>
	);
}

const styles = StyleSheet.create({
	header: {
		backgroundColor: '#efc',
		height: 50,
	},
	headerText: {
		color: 'red',
	},
	content: {
		marginVertical: 10,
		height: 50,
		backgroundColor: '#ef0',
		overflow: 'hidden',
	},
});


@jacklj
Copy link

jacklj commented Feb 18, 2022

Your _renderSectionTitle function is also rendering the section content (in addition to _renderContent):

	const _renderSectionTitle = (section) => {
		return (
			<View style={styles.content}>
				<Text>{section.content}</Text>
			</View>
		);
	}

This is copied from the example in the Readme (it's a bit of an odd example, but shows that the section title can also be rendered dynamically from the sections list).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants