To achieve placing an avatar on the top left and a “+” icon on the top right of your screen in React Native without using React Native Elements’ header (to avoid its default blue styling), you can follow these steps using react-native-safe-area-view for safe area handling and standard React Native components for layout:
First, ensure you have react-native-safe-area-view installed in your project. You can install it using npm or yarn:
npm install react-native-safe-area-view
# or
yarn add react-native-safe-area-view
Create your HomePage component where you want to display the avatar and the “+” icon:
import React from "react"; import { View, StyleSheet, Text } from "react-native"; import { Avatar, Icon } from "react-native-elements"; import { useSafeAreaInsets } from "react-native-safe-area-context"; const HomePage = () => { const insets = useSafeAreaInsets(); return ( <View style={[styles.container, { paddingTop: insets.top }]}> <View style={styles.header}> <Avatar size="small" rounded source={{ uri: "http://www.example.com/avatar.jpg", // Replace with your avatar URL }} onPress={() => console.log("Left Clicked!")} activeOpacity={0.7} /> <Icon name="add-circle-outline" type="ionicon" color="#00BB23" size={32} onPress={() => console.log("Right Clicked!")} /> </View> {/* Add your main content below */} <View style={styles.content}> <Text>Your main content goes here.</Text> </View> </View> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", // Adjust as per your app's theme }, header: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", paddingHorizontal: 16, paddingBottom: 8, // Adjust spacing as needed }, content: { flex: 1, justifyContent: "center", alignItems: "center", }, }); export default HomePage;
By following these steps, you can achieve a clean layout with an avatar on the top left and a “+” icon on the top right, effectively replacing the need for React Native Elements’ header and avoiding any unwanted styling conflicts. Adjust the styles and components further to fit your specific application’s design and functionality requirements.