Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ web-build/
# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

ios/
ios/
android/
5 changes: 2 additions & 3 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module.exports = {
slug: "hydra",
version: packageJson.version,
newArchEnabled: true,
runtimeVersion: {
policy: 'appVersion',
},
runtimeVersion: packageJson.version,
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "hydra",
Expand All @@ -33,6 +31,7 @@ module.exports = {
},
},
android: {
package: "com.dmilin.hydra",
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#000000"
Expand Down
65 changes: 35 additions & 30 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { registerRootComponent } from "expo";
import { useFonts } from "expo-font";
import { SplashScreen } from "expo-router";
import React, { useEffect, useState } from "react";
import { AppState, LogBox } from "react-native";
import { AppState, LogBox, Platform } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { enableFreeze } from "react-native-screens";

Expand Down Expand Up @@ -59,7 +60,9 @@ Sentry.init({
SplashScreen.preventAutoHideAsync();

// Tells non visble tabs and screens to not rerender in the background
enableFreeze(true);
if (Platform.OS !== "android") {
enableFreeze(true);
}

function RootLayout() {
const { success: migrationsComplete, error } = useMigrations(db, migrations);
Expand Down Expand Up @@ -105,34 +108,36 @@ function RootLayout() {
migrationsComplete &&
fontsLoaded &&
dbMaintenanceDone && (
<SafeAreaProvider>
<AccountProvider>
<SubscriptionsProvider>
<SettingsProvider>
<TabScrollProvider>
<NavigationProvider>
<ActionSheetProvider>
<ActionSheetBgProvider>
<InboxProvider>
<ModalProvider>
<MediaViewerProvider>
<SubredditProvider>
<StartupModalProvider>
<SubscribeToHydra />
<Tabs />
</StartupModalProvider>
</SubredditProvider>
</MediaViewerProvider>
</ModalProvider>
</InboxProvider>
</ActionSheetBgProvider>
</ActionSheetProvider>
</NavigationProvider>
</TabScrollProvider>
</SettingsProvider>
</SubscriptionsProvider>
</AccountProvider>
</SafeAreaProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<AccountProvider>
<SubscriptionsProvider>
<SettingsProvider>
<TabScrollProvider>
<NavigationProvider>
<ActionSheetProvider>
<ActionSheetBgProvider>
<InboxProvider>
<ModalProvider>
<MediaViewerProvider>
<SubredditProvider>
<StartupModalProvider>
<SubscribeToHydra />
<Tabs />
</StartupModalProvider>
</SubredditProvider>
</MediaViewerProvider>
</ModalProvider>
</InboxProvider>
</ActionSheetBgProvider>
</ActionSheetProvider>
</NavigationProvider>
</TabScrollProvider>
</SettingsProvider>
</SubscriptionsProvider>
</AccountProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
)
);
}
Expand Down
1 change: 1 addition & 0 deletions components/Modals/QuickSubredditSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function QuickSubredditSearch({

return (
<Animated.View
pointerEvents={show ? "auto" : "none"}
style={[
styles.container,
{
Expand Down
19 changes: 10 additions & 9 deletions contexts/ActionSheetBgProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ export function ActionSheetBgProvider({ children }: React.PropsWithChildren) {

return (
<ActionSheetBgContext.Provider value={value}>
<Animated.View
style={[
styles.actionSheetBg,
{
opacity: actionSheetBgOpacity,
pointerEvents: isActionSheetShowing ? "auto" : "none",
},
]}
/>
{isActionSheetShowing && (
<Animated.View
style={[
styles.actionSheetBg,
{
opacity: actionSheetBgOpacity,
},
]}
/>
)}
{children}
</ActionSheetBgContext.Provider>
);
Expand Down
42 changes: 8 additions & 34 deletions contexts/ModalContext.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
ReactNode,
createContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { Animated, StyleSheet, useWindowDimensions } from "react-native";
import { ReactNode, createContext, useMemo, useState } from "react";
import { StyleSheet, View } from "react-native";

type ModalContextType = {
setModal: (modal?: ReactNode) => void;
Expand All @@ -20,16 +13,6 @@ export const ModalContext = createContext(initialModalContext);

export function ModalProvider({ children }: React.PropsWithChildren) {
const [modal, setModal] = useState<ReactNode>(null);
const { height } = useWindowDimensions();
const modalPosition = useRef(new Animated.Value(height)).current;

useEffect(() => {
Animated.spring(modalPosition, {
toValue: modal ? 0 : height,
bounciness: 2,
useNativeDriver: true,
}).start();
}, [modal]);

/**
* Since this provider only provides functions, we need to memoize the value
Expand All @@ -44,28 +27,19 @@ export function ModalProvider({ children }: React.PropsWithChildren) {

return (
<ModalContext.Provider value={value}>
<Animated.View
style={[
styles.modalContainer,
{
transform: [
{
translateY: modalPosition,
},
],
},
]}
>
{modal}
</Animated.View>
{children}
{modal && <View style={styles.modalContainer}>{modal}</View>}
</ModalContext.Provider>
);
}

const styles = StyleSheet.create({
modalContainer: {
position: "relative",
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 1000,
},
});
82 changes: 43 additions & 39 deletions contexts/StackFutureContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
useEffect,
useRef,
} from "react";
import { Animated, useWindowDimensions } from "react-native";
import { Animated, Platform, useWindowDimensions } from "react-native";

import { StackParamsList } from "../app/stack";

Expand Down Expand Up @@ -66,46 +66,50 @@ export function StackFutureProvider({
clearFuture: () => (futureRoutes.current = []),
}}
>
<Animated.View
style={{
width: "100%",
height: "100%",
}}
onStartShouldSetResponderCapture={(e) => {
gestureStart.current = {
x: e.nativeEvent.pageX,
y: e.nativeEvent.pageY,
};
return false;
}}
onMoveShouldSetResponder={() =>
!!gestureStart.current &&
width - gestureStart.current.x < 30 &&
futureRoutes.current.length > 0
}
onResponderMove={(e) => {
if (!gestureStart.current) return false;
const deltaX = gestureStart.current.x - e.nativeEvent.pageX;
const deltaY = e.nativeEvent.pageY - gestureStart.current.y;
const angleDegrees = Math.abs(
Math.atan2(deltaY, deltaX) * (180 / Math.PI),
);
if (angleDegrees > 15 && deltaY > 30) {
gestureStart.current = null;
{Platform.OS === "android" ? (
children
) : (
<Animated.View
style={{
width: "100%",
height: "100%",
}}
onStartShouldSetResponderCapture={(e) => {
gestureStart.current = {
x: e.nativeEvent.pageX,
y: e.nativeEvent.pageY,
};
return false;
}}
onMoveShouldSetResponder={() =>
!!gestureStart.current &&
width - gestureStart.current.x < 30 &&
futureRoutes.current.length > 0
}
if (deltaX > 15 && angleDegrees < 15) {
const popped = futureRoutes.current.pop();
if (!popped) return false;
navigation.push(popped.name as any, popped.params as any);
gestureStart.current = null;
return true;
}
return false;
}}
>
{children}
</Animated.View>
onResponderMove={(e) => {
if (!gestureStart.current) return false;
const deltaX = gestureStart.current.x - e.nativeEvent.pageX;
const deltaY = e.nativeEvent.pageY - gestureStart.current.y;
const angleDegrees = Math.abs(
Math.atan2(deltaY, deltaX) * (180 / Math.PI),
);
if (angleDegrees > 15 && deltaY > 30) {
gestureStart.current = null;
return false;
}
if (deltaX > 15 && angleDegrees < 15) {
const popped = futureRoutes.current.pop();
if (!popped) return false;
navigation.push(popped.name as any, popped.params as any);
gestureStart.current = null;
return true;
}
return false;
}}
>
{children}
</Animated.View>
)}
</StackFutureContext.Provider>
);
}
Loading