Skip to content

Commit

Permalink
make loading less states less obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Sep 25, 2024
1 parent 803b3a8 commit 39fbc62
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 57 deletions.
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#191A20"
"backgroundColor": "#fff"
},
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.bacon.mdex",
"infoPlist": {
"UIViewControllerBasedStatusBarAppearance": true,
"ITSAppUsesNonExemptEncryption": false
}
},
Expand Down
23 changes: 11 additions & 12 deletions app/(index,orders,products,analytics)/_layout.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export default function RootLayout({ segment }: { segment: string }) {
return (
<Stack
screenOptions={{
headerTransparent: true,
headerBlurEffect: "prominent",
headerShadowVisible: true,
headerLargeTitleShadowVisible: false,
headerStyle: {
// Hack to ensure the collapsed small header shows the shadow / border.
backgroundColor: "rgba(255,255,255,0.01)",
},
headerLargeStyle: {
backgroundColor: PlatformColor("systemGroupedBackgroundColor"), // Color of your background
},
contentStyle: {
backgroundColor: PlatformColor("systemGroupedBackgroundColor"),
},
Expand All @@ -27,18 +38,6 @@ export default function RootLayout({ segment }: { segment: string }) {
return <ProfileButton segment={segment} />;
},

headerTransparent: true,
headerBlurEffect: "prominent",
headerShadowVisible: true,
headerLargeTitleShadowVisible: false,
headerStyle: {
// Hack to ensure the collapsed small header shows the shadow / border.
backgroundColor: "rgba(255,255,255,0.01)",
},
headerLargeStyle: {
backgroundColor: PlatformColor("systemGroupedBackgroundColor"), // Color of your background
},

//
...(name !== "index"
? {
Expand Down
21 changes: 12 additions & 9 deletions app/(index,orders,products,analytics)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ export default function IndexRoute() {
}
}}
ref={useScrollRef()}
{...extraProps}
navigate={router.navigate}
dom={{
contentInsetAdjustmentBehavior: "automatic",
automaticallyAdjustsScrollIndicatorInsets: true,
onLoadEnd(event) {
// Keep the splash screen open until the DOM content has loaded.
setTimeout(() => {
SplashScreen.hideAsync();
}, 1);
},
}}
/>
);
}
Expand All @@ -46,11 +56,4 @@ async function notify() {
trigger: null,
});
}

const extraProps = {
navigate: router.navigate,
dom: {
contentInsetAdjustmentBehavior: "automatic",
automaticallyAdjustsScrollIndicatorInsets: true,
},
} as const;
import * as SplashScreen from "expo-splash-screen";
4 changes: 3 additions & 1 deletion app/(index,orders,products,analytics)/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default function Settings() {
}
}}
/>
<StatusBar barStyle="light-content" />
{process.env.EXPO_OS === "android" && (
<StatusBar barStyle="light-content" />
)}
</>
);
}
11 changes: 6 additions & 5 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import { House, ShoppingCart, Package, LineChart } from "lucide-react-native";
import * as Haptics from "expo-haptics";
import { BlurView } from "expo-blur";
import { StyleSheet } from "react-native";
import { HapticTab } from "@/components/haptic-tab";
import * as SplashScreen from "expo-splash-screen";

SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
// TODO: Add tab bar
if (process.env.EXPO_OS === "web") return <Slot />;
return (
<Tabs
screenOptions={{
lazy: false,
tabBarButton: HapticTab,
headerShown: false,
tabBarActiveTintColor: "rgb(15, 23, 42)",
tabBarStyle: {
Expand All @@ -23,11 +29,6 @@ export default function RootLayout() {
/>
),
}}
screenListeners={{
tabPress: () => {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
},
}}
>
<Tabs.Screen
name="(index)"
Expand Down
8 changes: 5 additions & 3 deletions components/global-button-haptics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ export function useGlobalButtonHaptics(haptics?: (size: number) => void) {
useEffect(() => {
if (!haptics) return;

const listener = (event: MouseEvent) => {
const listener = (event: TouchEvent) => {
// Check if the clicked element is a button
if (event.target?.tagName === "BUTTON") {
haptics(getSizeScale(event.target as HTMLButtonElement));
}
};
// Global event listener for clicks
document.addEventListener("click", listener);
// document.addEventListener("click", listener);
// Global event listener for touch start
document.addEventListener("touchstart", listener);

return () => {
document.removeEventListener("click", listener);
document.removeEventListener("touchstart", listener);
};
}, [haptics]);

Expand Down
18 changes: 18 additions & 0 deletions components/haptic-tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BottomTabBarButtonProps } from "@react-navigation/bottom-tabs";
import { PlatformPressable } from "@react-navigation/elements";
import * as Haptics from "expo-haptics";

export function HapticTab(props: BottomTabBarButtonProps) {
return (
<PlatformPressable
{...props}
onPressIn={(ev) => {
if (process.env.EXPO_OS !== "web") {
// Add a soft haptic feedback when pressing down on the tabs.
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}
props.onPressIn?.(ev);
}}
/>
);
}
Binary file added components/mdx/sci-fi.avif
Binary file not shown.
Binary file removed components/mdx/sci-fi.jpg
Binary file not shown.
4 changes: 2 additions & 2 deletions components/mdx/story.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DOM Markdown

![Embedded Image](./sci-fi.jpg)
![Embedded Image](./sci-fi.avif)

In the year 2473, humanity had long since spread beyond Earth, colonizing planets and moons in distant star systems. Amidst this interstellar expansion, the **ISV Nomad**, a lone exploratory vessel, drifted through the vast void of space, its mission: to investigate the unknown regions at the edge of the Milky Way.

Expand Down Expand Up @@ -78,7 +78,7 @@ Image cropping with `react-mobile-cropper`.
import Cropper from "@/components/mdx/mobile-cropper";

<Cropper
image={(process.env.EXPO_DOM_BASE_URL || "") + "/placeholder-user.jpg"}
image={(process.env.EXPO_DOM_BASE_URL || "") + "/placeholder-user.avif"}
style={{
height: 300,
maxHeight: 300,
Expand Down
1 change: 0 additions & 1 deletion components/shad/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
MoreVertical,
Truck,
} from "lucide-react";
import { useEffect } from "react";
import { useGlobalButtonHaptics } from "../global-button-haptics";

export default function DashboardRoute({
Expand Down
22 changes: 11 additions & 11 deletions components/shad/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ShadLayout from "./shad-layout";
import StoryWrapper from "../mdx/mdx-route";
import { useGlobalButtonHaptics } from "../global-button-haptics";
// import { useEffect } from "react";

export default function SettingsRoute({
navigate,
Expand All @@ -14,17 +13,18 @@ export default function SettingsRoute({
onButtonClick: (size: number) => Promise<void>;
}) {
useGlobalButtonHaptics(onButtonClick);
// useEffect(() => {
// import("eruda").then((eruda) => eruda.default.init());
// }, []);

return (
<ShadLayout navigate={navigate} select>
<main className="grid flex-1 items-start gap-4 p-4 sm:px-6 sm:py-0 md:gap-8">
<div className="mx-auto grid max-w-[59rem] flex-1 auto-rows-max gap-4">
<StoryWrapper />
</div>
</main>
</ShadLayout>
<>
<div className="animate-fade-in">
<ShadLayout navigate={navigate} select>
<main className="grid flex-1 items-start gap-4 p-4 sm:px-6 sm:py-0 md:gap-8">
<div className="mx-auto grid max-w-[59rem] flex-1 auto-rows-max gap-4">
<StoryWrapper />
</div>
</main>
</ShadLayout>
</div>
</>
);
}
4 changes: 3 additions & 1 deletion components/shad/shad-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default function ShadLayout({
}

return (
<ShadLayoutFull select={select} navigate={navigate} children={children} />
<div className="animate-fade-in">
<ShadLayoutFull select={select} navigate={navigate} children={children} />
</div>
);
}
2 changes: 1 addition & 1 deletion components/shad/shad-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export function Header() {
className="overflow-hidden rounded-full"
>
<img
src={baseUrl + "/evanbacon.jpg"}
src={baseUrl + "/evanbacon.avif"}
width={36}
height={36}
alt="Avatar"
Expand Down
10 changes: 1 addition & 9 deletions components/touchable-impact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const TouchableImpact = React.forwardRef<
React.ComponentProps<typeof TouchableBase> & {
impact?: boolean | Haptics.ImpactFeedbackStyle;
}
>(({ onPress, onPressIn, impact = true, ...props }, ref) => {
>(({ onPressIn, impact = true, ...props }, ref) => {
return (
<TouchableBase
ref={ref}
Expand All @@ -20,14 +20,6 @@ export const TouchableImpact = React.forwardRef<
}
onPressIn?.(...props);
}}
onPress={(...props) => {
if (impact && process.env.EXPO_OS !== "web") {
Haptics.impactAsync(
impact === true ? Haptics.ImpactFeedbackStyle.Light : impact
);
}
onPress?.(...props);
}}
{...props}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"lint": "expo lint",
"prebuild": "expo prebuild --template ./vendor/expo-template-bare-minimum-51.0.27.tgz",
"predeploy:web": "expo export -p web",
"deploy:web": "netlify deploy --dir dist"
"deploy:web": "netlify deploy --dir dist",
"prepare": "npx patch-package"
},
"dependencies": {
"@bacons/mdx": "^0.3.8",
Expand Down
43 changes: 43 additions & 0 deletions patches/react-native-webview+13.8.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/node_modules/react-native-webview/apple/RNCWebViewImpl.m b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
index ed3a81a..7d361e7 100644
--- a/node_modules/react-native-webview/apple/RNCWebViewImpl.m
+++ b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
@@ -474,9 +474,12 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
return wkWebViewConfig;
}

-- (void)didMoveToWindow
+- (void)initializeWebView
{
- if (self.window != nil && _webView == nil) {
+ @synchronized (self) {
+ if (_webView != nil) {
+ return;
+ }
WKWebViewConfiguration *wkWebViewConfig = [self setUpWkWebViewConfig];
_webView = [[RNCWKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
[self setBackgroundColor: _savedBackgroundColor];
@@ -529,6 +532,23 @@ - (void)didMoveToWindow
[self setKeyboardDisplayRequiresUserAction: _savedKeyboardDisplayRequiresUserAction];
[self visitSource];
}
+}
+
+// react-native-mac os does not support didMoveToSuperView
+#if !TARGET_OS_OSX
+- (void)didMoveToSuperview
+{
+ if (self.superview != nil && _webView == nil) {
+ [self initializeWebView];
+ }
+}
+#endif // !TARGET_OS_OSX
+
+- (void)didMoveToWindow
+{
+ if (self.window != nil && _webView == nil) {
+ [self initializeWebView];
+ }
#if !TARGET_OS_OSX
// Allow this object to recognize gestures
if (self.menuItems != nil) {
Binary file added public/evanbacon.avif
Binary file not shown.
Binary file added public/placeholder-user.avif
Binary file not shown.
Binary file removed public/placeholder-user.jpg
Binary file not shown.
5 changes: 5 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ module.exports = {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
"fade-in": {
from: { opacity: "0" },
to: { opacity: "1" },
},
},
animation: {
"fade-in": "fade-in 0.3s ease-out",
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
Expand Down

0 comments on commit 39fbc62

Please sign in to comment.