Skip to content

Commit

Permalink
feat: search on header
Browse files Browse the repository at this point in the history
  • Loading branch information
mrevanzak committed Oct 29, 2023
1 parent d61eb67 commit 0721262
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 9 deletions.
23 changes: 16 additions & 7 deletions apps/expo/src/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function TabsLayout() {
borderTopRightRadius: 15,
height: 70,
},
headerShown: false,
}}
>
<Tabs.Screen
Expand Down Expand Up @@ -45,13 +46,21 @@ export default function TabsLayout() {
left: 2,
},
tabBarIcon: ({ focused }) => (
<Ionicons
name={
focused ? "md-checkmark-circle-outline" : "md-checkmark-circle"
}
size={70}
color="#FDBC12"
/>
<Button
avoidInnerPadding
avoidMinWidth
backgroundColor="transparent"
>
<Ionicons
name={
focused
? "md-checkmark-circle-outline"
: "md-checkmark-circle"
}
size={70}
color="#FDBC12"
/>
</Button>
),
}}
/>
Expand Down
11 changes: 9 additions & 2 deletions apps/expo/src/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Slot } from "expo-router";
import { Stack } from "expo-router";
import { StatusBar } from "expo-status-bar";
import Header from "@/components/Header";
import { TRPCProvider } from "@/utils/api";

export default function RootLayout() {
return (
<TRPCProvider>
<Slot />
<Stack
screenOptions={{
header: (props) => <Header {...props} />,
}}
>
<Stack.Screen name="index" options={{ headerShown: false }} />
</Stack>
<StatusBar />
</TRPCProvider>
);
Expand Down
6 changes: 6 additions & 0 deletions apps/expo/src/app/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import { Text } from "react-native-ui-lib";

export default function SearchScreen() {
return <Text>search</Text>;
}
68 changes: 68 additions & 0 deletions apps/expo/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Button, TextField } from "react-native-ui-lib";
import { Link, usePathname } from "expo-router";
import { MaterialIcons } from "@expo/vector-icons";
import type { BottomTabHeaderProps } from "@react-navigation/bottom-tabs";
import type { NativeStackHeaderProps } from "@react-navigation/native-stack";

export default function Header(
props: BottomTabHeaderProps | NativeStackHeaderProps,
) {
const pathname = usePathname();
const isSearchScreen = pathname === "/search";

return (
<SafeAreaView className="flex-row bg-[#157DC1]" {...props}>
{isSearchScreen && (
<Link href="/(tabs)/home" asChild>
<Button
avoidInnerPadding
animateLayout
paddingL-s4
bg-transparent
centerH
iconSource={() => (
<MaterialIcons name="arrow-back-ios" size={24} color="white" />
)}
/>
</Link>
)}
<Link href="/search" asChild disabled={isSearchScreen}>
<Button
avoidInnerPadding
flex-1
bg-transparent
disabledBackgroundColor="transparent"
animateLayout
>
<TextField
placeholder="Search"
containerStyle={{
backgroundColor: "white",
marginHorizontal: 10,
marginVertical: 20,
height: 30,
borderRadius: 8,
flex: 1,
}}
fieldStyle={{
marginLeft: 10,
}}
readonly={!isSearchScreen}
// onChangeText={onChangeText}
enableErrors
// validate={["required", "email", (value) => value.length > 6]}
// validationMessage={[
// "Field is required",
// "Email is invalid",
// "Password is too short",
// ]}
maxLength={30}
/>
</Button>
</Link>
{/* </View> */}
</SafeAreaView>
);
}

0 comments on commit 0721262

Please sign in to comment.