From cd10200c64572ab09112ddda55fc1057bac233ab Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Fri, 15 Mar 2024 00:42:22 +0000
Subject: mobile: Fix keyboard interactions in search and signin form

---
 apps/mobile/app/signin.tsx | 111 +++++++++++++++++++++++++--------------------
 1 file changed, 62 insertions(+), 49 deletions(-)

(limited to 'apps/mobile/app/signin.tsx')

diff --git a/apps/mobile/app/signin.tsx b/apps/mobile/app/signin.tsx
index 63e48f22..da7e2fea 100644
--- a/apps/mobile/app/signin.tsx
+++ b/apps/mobile/app/signin.tsx
@@ -1,5 +1,12 @@
 import { useEffect, useState } from "react";
-import { Text, View } from "react-native";
+import {
+  Keyboard,
+  KeyboardAvoidingView,
+  Platform,
+  Text,
+  TouchableWithoutFeedback,
+  View,
+} from "react-native";
 import { useRouter } from "expo-router";
 import Logo from "@/components/Logo";
 import { Button } from "@/components/ui/Button";
@@ -48,53 +55,59 @@ export default function Signin() {
   };
 
   return (
-    <View className="flex h-full flex-col justify-center gap-2 px-4">
-      <View className="items-center">
-        <Logo />
-      </View>
-      {error && (
-        <Text className="w-full text-center text-red-500">{error}</Text>
-      )}
-      <View className="gap-2">
-        <Text className="font-bold">Server Address</Text>
-        <Input
-          className="w-full"
-          placeholder="Server Address"
-          value={settings.address}
-          autoCapitalize="none"
-          keyboardType="url"
-          onEndEditing={(e) =>
-            setSettings({ ...settings, address: e.nativeEvent.text })
-          }
-        />
-      </View>
-      <View className="gap-2">
-        <Text className="font-bold">Email</Text>
-        <Input
-          className="w-full"
-          placeholder="Email"
-          keyboardType="email-address"
-          autoCapitalize="none"
-          value={formData.email}
-          onChangeText={(e) => setFormData((s) => ({ ...s, email: e }))}
-        />
-      </View>
-      <View className="gap-2">
-        <Text className="font-bold">Password</Text>
-        <Input
-          className="w-full"
-          placeholder="Password"
-          secureTextEntry
-          value={formData.password}
-          onChangeText={(e) => setFormData((s) => ({ ...s, password: e }))}
-        />
-      </View>
-      <Button
-        className="w-full"
-        label="Sign In"
-        onPress={onSignin}
-        disabled={isPending}
-      />
-    </View>
+    <KeyboardAvoidingView
+      behavior={Platform.OS === "ios" ? "padding" : "height"}
+    >
+      <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
+        <View className="flex h-full flex-col justify-center gap-2 px-4">
+          <View className="items-center">
+            <Logo />
+          </View>
+          {error && (
+            <Text className="w-full text-center text-red-500">{error}</Text>
+          )}
+          <View className="gap-2">
+            <Text className="font-bold">Server Address</Text>
+            <Input
+              className="w-full"
+              placeholder="Server Address"
+              value={settings.address}
+              autoCapitalize="none"
+              keyboardType="url"
+              onEndEditing={(e) =>
+                setSettings({ ...settings, address: e.nativeEvent.text })
+              }
+            />
+          </View>
+          <View className="gap-2">
+            <Text className="font-bold">Email</Text>
+            <Input
+              className="w-full"
+              placeholder="Email"
+              keyboardType="email-address"
+              autoCapitalize="none"
+              value={formData.email}
+              onChangeText={(e) => setFormData((s) => ({ ...s, email: e }))}
+            />
+          </View>
+          <View className="gap-2">
+            <Text className="font-bold">Password</Text>
+            <Input
+              className="w-full"
+              placeholder="Password"
+              secureTextEntry
+              value={formData.password}
+              onChangeText={(e) => setFormData((s) => ({ ...s, password: e }))}
+            />
+          </View>
+          <Button
+            className="w-full"
+            label="Sign In"
+            onPress={onSignin}
+            disabled={isPending}
+          />
+        </View>
+      </TouchableWithoutFeedback>
+    </KeyboardAvoidingView>
   );
 }
-- 
cgit v1.3-1-g0d28

