5.2.5.3 헤더의 좌측, 타이틀, 우측 영역에 다른 컴포넌트 보여주기
헤더의 좌측, 타이틀, 우측 영역에 원래 UI가 아닌 다른 컴포넌트를 보여주는 방법을 알아보겠습니다. App 컴포넌트에서 Detail 화면의 옵션을 다음과 같이 변경해보세요.
App.js
import React from 'react'; import {NavigationContainer} from '@react-navigation/native'; import {createNativeStackNavigator} from '@react-navigation/native-stack'; import HomeScreen from './screens/HomeScreen'; import DetailScreen from './screens/DetailScreen'; import {View, Text, TouchableOpacity} from 'react-native'; const Stack (); function () { return ( <NavigationContainer> <Stack.Navigator initialRouteName="Home"> <Stack.Screen name="Home" (...) /> <Stack.Screen name="Detail" component={DetailScreen} options={{ headerLeft: ({onPress}) => ( <TouchableOpacity onPress={onPress}> <Text>Left</Text> </TouchableOpacity> ), headerTitle: ({children}) => ( <View> <Text>{children}</Text> </View> ), headerRight: () => ( <View> <Text>Right</Text> </View> ), }} /> </Stack.Navigator> </NavigationContainer> ); } export default App;