アイコン処理用function分離

This commit is contained in:
harukin-DeskMini 2023-01-30 02:51:57 +09:00
parent 67f9b8b698
commit 556b04e3b0

30
App.js
View File

@ -35,12 +35,12 @@ export default function App() {
<Tab.Navigator> <Tab.Navigator>
<Tab.Screen <Tab.Screen
name="login" name="login"
component={top} component={Top}
options={{ options={{
tabBarLabel: "位置情報", tabBarLabel: "位置情報",
headerTransparent: true, headerTransparent: true,
gestureEnabled: true, gestureEnabled: true,
tabBarIcon: () => <AntDesign name="barchart" size={32} />, tabBarIcon: initIcon("barchart", "AntDesign"),
}} }}
/> />
<Tab.Screen <Tab.Screen
@ -50,7 +50,7 @@ export default function App() {
tabBarLabel: "リンク", tabBarLabel: "リンク",
headerTransparent: true, headerTransparent: true,
gestureEnabled: true, gestureEnabled: true,
tabBarIcon: () => <Ionicons name="ios-radio" size={32} />, tabBarIcon: initIcon("ios-radio", "Ionicons"),
}} }}
/> />
<Tab.Screen <Tab.Screen
@ -60,21 +60,41 @@ export default function App() {
tabBarLabel: "運行情報", tabBarLabel: "運行情報",
headerTransparent: true, headerTransparent: true,
gestureEnabled: true, gestureEnabled: true,
tabBarIcon: () => <Ionicons name="md-train" size={32} />, tabBarIcon: initIcon("md-train", "Ionicons"),
}} }}
/> />
</Tab.Navigator> </Tab.Navigator>
</NavigationContainer> </NavigationContainer>
); );
} }
const top = ({ navigation }) => {
const initIcon = (name, type, props) => {
switch (type) {
case "Ionicons":
return ({ focused, color, size }) => (
<Ionicons name={name} size={32} color={focused ? "#0099CC" : "black"} />
);
case "AntDesign":
return ({ focused, color, size }) => (
<AntDesign
name={name}
size={32}
color={focused ? "#0099CC" : "black"}
/>
);
}
};
const Top = ({ navigation }) => {
const webview = useRef(); const webview = useRef();
//地図用 //地図用
const [mapsStationData, setMapsStationData] = useState(undefined); const [mapsStationData, setMapsStationData] = useState(undefined);
useEffect(() => { useEffect(() => {
getStationList2().then(setMapsStationData); getStationList2().then(setMapsStationData);
}, []); }, []);
useEffect(() => { useEffect(() => {
const unsubscribe = navigation.addListener("tabLongPress", (e) => { const unsubscribe = navigation.addListener("tabLongPress", (e) => {
navigation.navigate("favoriteList"); navigation.navigate("favoriteList");