@marktiderman/genesis-ui-native 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -0
- package/dist/chunk-7PCWEY6R.js +27 -0
- package/dist/chunk-7PCWEY6R.js.map +1 -0
- package/dist/chunk-D5RKSPMH.js +24 -0
- package/dist/chunk-D5RKSPMH.js.map +1 -0
- package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
- package/dist/chunk-EFXCJ5AN.js.map +1 -0
- package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
- package/dist/chunk-ERHGCWTY.js.map +1 -0
- package/dist/{chunk-3LK5ZJ4M.js → chunk-FIITITXO.js} +67 -108
- package/dist/chunk-FIITITXO.js.map +1 -0
- package/dist/chunk-FZY2IXOX.js +1559 -0
- package/dist/chunk-FZY2IXOX.js.map +1 -0
- package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
- package/dist/chunk-W7BK3ARU.js.map +1 -0
- package/dist/components/index.d.ts +143 -17
- package/dist/components/index.js +6 -4
- package/dist/data/index.d.ts +7 -1
- package/dist/data/index.js +31 -6
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/icons/lucide.d.ts +7 -0
- package/dist/icons/lucide.js +47 -0
- package/dist/icons/lucide.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/dist/layouts/index.d.ts +399 -7
- package/dist/layouts/index.js +3 -3
- package/dist/native-modules-BSVaEb3D.d.ts +206 -0
- package/package.json +34 -5
- package/src/__tests__/fake-modules.tsx +134 -0
- package/src/__tests__/native-modules-lists.test.tsx +70 -0
- package/src/__tests__/native-modules.test.tsx +631 -0
- package/src/components/__tests__/sheet.test.tsx +193 -0
- package/src/components/__tests__/toast.test.tsx +15 -0
- package/src/components/avatar.tsx +69 -16
- package/src/components/date-time-picker.tsx +128 -10
- package/src/components/drawer.tsx +158 -68
- package/src/components/dropdown-menu.tsx +7 -6
- package/src/components/glass-surface.tsx +150 -0
- package/src/components/icon.tsx +66 -0
- package/src/components/image.tsx +89 -0
- package/src/components/index.ts +33 -2
- package/src/components/list-item.tsx +29 -9
- package/src/components/popover.tsx +12 -9
- package/src/components/segmented-control.tsx +7 -1
- package/src/components/sheet.tsx +276 -133
- package/src/components/skeleton.tsx +75 -53
- package/src/components/textarea.tsx +1 -0
- package/src/components/toast.tsx +185 -87
- package/src/data/NativeResourcePage.tsx +48 -3
- package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
- package/src/hooks/use-reduced-motion.ts +24 -10
- package/src/icon-names.ts +49 -0
- package/src/icons/lucide.ts +88 -0
- package/src/layouts/__tests__/apple-sign-in.test.tsx +97 -0
- package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
- package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
- package/src/layouts/__tests__/thread-page.test.tsx +128 -0
- package/src/layouts/apple-sign-in.tsx +136 -0
- package/src/layouts/auth-screen.tsx +17 -8
- package/src/layouts/auth.tsx +29 -19
- package/src/layouts/google-sign-in.tsx +42 -0
- package/src/layouts/inbox-page.tsx +408 -0
- package/src/layouts/index.ts +45 -2
- package/src/layouts/keyboard.tsx +61 -9
- package/src/layouts/notifications-page.tsx +133 -16
- package/src/layouts/screen-container.tsx +6 -2
- package/src/layouts/settings-page.tsx +117 -14
- package/src/layouts/settings-sub-page.tsx +9 -3
- package/src/layouts/thread-page.tsx +444 -0
- package/src/native-modules.tsx +186 -0
- package/dist/chunk-3LK5ZJ4M.js.map +0 -1
- package/dist/chunk-5HRGIA6F.js.map +0 -1
- package/dist/chunk-F2TGDKOO.js +0 -43
- package/dist/chunk-F2TGDKOO.js.map +0 -1
- package/dist/chunk-TXJT55JC.js.map +0 -1
- package/dist/chunk-U2SPACTV.js +0 -876
- package/dist/chunk-U2SPACTV.js.map +0 -1
- package/dist/chunk-ULS7I6ZS.js.map +0 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @feat:inbox-thread
|
|
2
|
+
import { forwardRef, useImperativeHandle, type ReactNode } from "react";
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { ThreadPage, getThreadPageStackOptions, readReceiptFor, type ThreadMessage } from "../thread-page";
|
|
6
|
+
import { KeyboardScrollProvider, type KeyboardScrollProps } from "../keyboard";
|
|
7
|
+
|
|
8
|
+
const messages: ThreadMessage[] = [
|
|
9
|
+
{ id: "1", body: "The save button does nothing", mine: true, timestamp: "2026-10-24T09:00:00Z" },
|
|
10
|
+
{ id: "2", body: "Thanks, we're on it.", mine: false, authorName: "Support", timestamp: "2026-10-24T09:05:00Z" },
|
|
11
|
+
{ id: "3", body: "It happens on every screen", mine: true, timestamp: "2026-10-24T09:10:00Z", attachments: [{ id: "s", uri: "file:///shot.png", width: 390, height: 844 }] },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const composer = (over: Partial<Parameters<typeof ThreadPage>[0]["composer"] & object> = {}) => ({
|
|
15
|
+
value: "",
|
|
16
|
+
onChangeText: vi.fn(),
|
|
17
|
+
onSend: vi.fn(),
|
|
18
|
+
...over,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("readReceiptFor", () => {
|
|
22
|
+
it("is my newest message sent before the other side read the thread", () => {
|
|
23
|
+
expect(readReceiptFor(messages, "2026-10-24T09:11:00Z")).toBe("3");
|
|
24
|
+
expect(readReceiptFor(messages, "2026-10-24T09:06:00Z")).toBe("1");
|
|
25
|
+
expect(readReceiptFor(messages, "2026-10-24T08:00:00Z")).toBeNull();
|
|
26
|
+
expect(readReceiptFor(messages, null)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("never marks a message that is still sending or failed", () => {
|
|
30
|
+
const pending: ThreadMessage[] = [...messages, { id: "4", body: "x", mine: true, timestamp: "2026-10-24T09:12:00Z", status: "sending" }];
|
|
31
|
+
expect(readReceiptFor(pending, "2026-10-24T09:20:00Z")).toBe("3");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("ThreadPage", () => {
|
|
36
|
+
it("renders messages oldest first, theirs with the author's name, and attachments", () => {
|
|
37
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} />);
|
|
38
|
+
const list = screen.getByTestId("t-messages");
|
|
39
|
+
const ids = [...list.querySelectorAll('[data-testid^="t-message-"]')].map((el) => el.getAttribute("data-testid")).filter((id) => !id!.endsWith("-time"));
|
|
40
|
+
expect(ids).toEqual(["t-message-1", "t-message-2", "t-message-3"]);
|
|
41
|
+
expect(list.textContent).toContain("Support");
|
|
42
|
+
expect(screen.getByTestId("t-attachment-s")).toBeTruthy();
|
|
43
|
+
expect(screen.getByTestId("t-message-1").getAttribute("aria-label")).toMatch(/^You, The save button does nothing/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("shows the read receipt under my newest read message", () => {
|
|
47
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} readAt="2026-10-24T09:11:00Z" readLabel="Seen" />);
|
|
48
|
+
expect(screen.getByTestId("t-read-receipt").textContent).toBe("Seen");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("sends from the composer, and won't send a blank message", () => {
|
|
52
|
+
const c = composer({ value: " " });
|
|
53
|
+
const { rerender } = render(<ThreadPage testID="t" messages={messages} composer={c} />);
|
|
54
|
+
expect((screen.getByTestId("t-composer-send") as HTMLButtonElement).disabled).toBe(true);
|
|
55
|
+
const typed = composer({ value: "More detail" });
|
|
56
|
+
rerender(<ThreadPage testID="t" messages={messages} composer={typed} />);
|
|
57
|
+
fireEvent.change(screen.getByTestId("t-composer-input"), { target: { value: "More detail!" } });
|
|
58
|
+
expect(typed.onChangeText).toHaveBeenCalledWith("More detail!");
|
|
59
|
+
fireEvent.click(screen.getByTestId("t-composer-send"));
|
|
60
|
+
expect(typed.onSend).toHaveBeenCalled();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("shows a spinner instead of Send while sending", () => {
|
|
64
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer({ value: "x", sending: true })} />);
|
|
65
|
+
expect(screen.getByTestId("t-composer-sending")).toBeTruthy();
|
|
66
|
+
expect(screen.queryByTestId("t-composer-send")).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("is read-only with no composer, and says why", () => {
|
|
70
|
+
render(<ThreadPage testID="t" messages={messages} composer={null} closedNotice="This report is closed." />);
|
|
71
|
+
expect(screen.queryByTestId("t-composer")).toBeNull();
|
|
72
|
+
expect(screen.getByTestId("t-closed").textContent).toBe("This report is closed.");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("retries a failed message on tap", () => {
|
|
76
|
+
const onRetry = vi.fn();
|
|
77
|
+
render(<ThreadPage testID="t" messages={[{ id: "f", body: "hi", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "failed", onRetry }]} composer={composer()} />);
|
|
78
|
+
expect(screen.getByTestId("t-message-f-time").textContent).toMatch(/Not sent/);
|
|
79
|
+
fireEvent.click(screen.getByTestId("t-message-f"));
|
|
80
|
+
expect(onRetry).toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("loads earlier messages from the top", () => {
|
|
84
|
+
const onLoadEarlier = vi.fn();
|
|
85
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} hasEarlier onLoadEarlier={onLoadEarlier} />);
|
|
86
|
+
fireEvent.click(screen.getByTestId("t-earlier"));
|
|
87
|
+
expect(onLoadEarlier).toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("fills the composer accessory and header slots", () => {
|
|
91
|
+
const Attach = ({ testID }: { testID: string }) => <button data-testid={testID}>Attach</button>;
|
|
92
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} header={<span data-testid="about" />} slots={{ composerAccessory: Attach }} />);
|
|
93
|
+
expect(screen.getByTestId("t-composer-accessory")).toBeTruthy();
|
|
94
|
+
expect(screen.getByTestId("about")).toBeTruthy();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("shows the empty state for a thread with no messages", () => {
|
|
98
|
+
render(<ThreadPage testID="t" messages={[]} composer={composer()} emptyTitle="Say hello" />);
|
|
99
|
+
expect(screen.getByTestId("t-empty").textContent).toContain("Say hello");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("falls back to a KeyboardAvoidingView without a keyboard scroll view", () => {
|
|
103
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} />);
|
|
104
|
+
expect(screen.getByTestId("t-kav")).toBeTruthy();
|
|
105
|
+
expect(screen.queryByTestId("t-keyboard")).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("puts the messages and the composer in the app's keyboard scroll view, and scrolls to the newest", () => {
|
|
109
|
+
const scrollToEnd = vi.fn();
|
|
110
|
+
const Scroll = forwardRef<unknown, KeyboardScrollProps & { children?: ReactNode }>(function Scroll({ children, testID }, ref) {
|
|
111
|
+
useImperativeHandle(ref, () => ({ scrollToEnd }));
|
|
112
|
+
return <div data-testid={testID}>{children}</div>;
|
|
113
|
+
});
|
|
114
|
+
render(
|
|
115
|
+
<KeyboardScrollProvider component={Scroll}>
|
|
116
|
+
<ThreadPage testID="t" messages={messages} composer={composer()} />
|
|
117
|
+
</KeyboardScrollProvider>,
|
|
118
|
+
);
|
|
119
|
+
const scroll = screen.getByTestId("t-keyboard");
|
|
120
|
+
expect(scroll.querySelector('[data-testid="t-composer-input"]')).toBeTruthy();
|
|
121
|
+
expect(screen.queryByTestId("t-kav")).toBeNull();
|
|
122
|
+
expect(scrollToEnd).toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("composes a standard header by default", () => {
|
|
126
|
+
expect(getThreadPageStackOptions({ headerTitle: "Report" })).toEqual({ title: "Report" });
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign in with Apple for `AuthScreen` / `SocialAuthRow`, drawn with Apple's
|
|
3
|
+
* own `AppleAuthenticationButton` (Apple's Human Interface Guidelines require
|
|
4
|
+
* its button; a look-alike gets an app rejected). Nothing here imports
|
|
5
|
+
* `expo-apple-authentication`: pass the module in.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import * as AppleAuthentication from "expo-apple-authentication";
|
|
9
|
+
*
|
|
10
|
+
* <AuthScreen providers={[appleProvider({ apple: AppleAuthentication, onPress: signIn }), google]} … />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* `appleProvider` returns `null` off iOS or without the module, and
|
|
14
|
+
* `AuthScreen` skips a `null` provider, so the same line works everywhere.
|
|
15
|
+
*
|
|
16
|
+
* @stability Beta
|
|
17
|
+
*/
|
|
18
|
+
import { useRef, useState, type ComponentType } from "react";
|
|
19
|
+
import { Platform, View, type ViewStyle } from "react-native";
|
|
20
|
+
import { useThemeMode } from "../hooks/use-theme-mode";
|
|
21
|
+
import type { SocialAuthProvider } from "./auth";
|
|
22
|
+
|
|
23
|
+
/** The parts of `expo-apple-authentication` the button uses. Pass the module itself. */
|
|
24
|
+
export interface AppleButtonModuleLike {
|
|
25
|
+
AppleAuthenticationButton: ComponentType<{
|
|
26
|
+
buttonType: number;
|
|
27
|
+
buttonStyle: number;
|
|
28
|
+
cornerRadius?: number;
|
|
29
|
+
onPress: () => void;
|
|
30
|
+
// The style the button is given, typed as the module types it: with `unknown` here the real
|
|
31
|
+
// module's button (which takes a ViewStyle) wasn't assignable under strictFunctionTypes.
|
|
32
|
+
style?: ViewStyle;
|
|
33
|
+
testID?: string;
|
|
34
|
+
accessibilityState?: { disabled?: boolean; busy?: boolean };
|
|
35
|
+
}>;
|
|
36
|
+
AppleAuthenticationButtonType: { SIGN_IN: number; CONTINUE: number; SIGN_UP: number };
|
|
37
|
+
AppleAuthenticationButtonStyle: { BLACK: number; WHITE: number; WHITE_OUTLINE: number };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AppleSignInButtonProps {
|
|
41
|
+
/** `expo-apple-authentication`. */
|
|
42
|
+
apple: AppleButtonModuleLike;
|
|
43
|
+
/** Usually `() => signInWithApple(supabase, AppleAuthentication, { digest })` from `@marktiderman/genesis-supabase/native`. */
|
|
44
|
+
onPress: () => void | Promise<void>;
|
|
45
|
+
/** Apple's wording: "Sign in with Apple", "Continue with Apple" (default) or "Sign up with Apple". */
|
|
46
|
+
type?: "sign-in" | "continue" | "sign-up";
|
|
47
|
+
/** `"auto"` (default): black in light mode, white in dark, as Apple recommends. */
|
|
48
|
+
appearance?: "auto" | "black" | "white" | "white-outline";
|
|
49
|
+
/** Default 10, to sit with Genesis buttons. */
|
|
50
|
+
cornerRadius?: number;
|
|
51
|
+
/** Default 44, the recommended touch target (Apple's HIG minimum for this button is 30pt). */
|
|
52
|
+
height?: number;
|
|
53
|
+
/** Dims the button and ignores presses. It is also ignored on its own while an `onPress` promise is pending, so a second tap can't open a second sheet. */
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
testID?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Apple's branded button, full width. Renders nothing off iOS. */
|
|
59
|
+
export function AppleSignInButton({
|
|
60
|
+
apple,
|
|
61
|
+
onPress,
|
|
62
|
+
type = "continue",
|
|
63
|
+
appearance = "auto",
|
|
64
|
+
cornerRadius = 10,
|
|
65
|
+
height = 44,
|
|
66
|
+
disabled,
|
|
67
|
+
testID = "apple-sign-in",
|
|
68
|
+
}: AppleSignInButtonProps) {
|
|
69
|
+
const mode = useThemeMode();
|
|
70
|
+
// A ref, not only state: two taps in the same frame both see the old state.
|
|
71
|
+
const pending = useRef(false);
|
|
72
|
+
const [busy, setBusy] = useState(false);
|
|
73
|
+
if (Platform.OS !== "ios") return null;
|
|
74
|
+
const press = async () => {
|
|
75
|
+
if (disabled || pending.current) return;
|
|
76
|
+
pending.current = true;
|
|
77
|
+
setBusy(true);
|
|
78
|
+
try {
|
|
79
|
+
await onPress();
|
|
80
|
+
} finally {
|
|
81
|
+
pending.current = false;
|
|
82
|
+
setBusy(false);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const inactive = !!disabled || busy;
|
|
86
|
+
const { AppleAuthenticationButton, AppleAuthenticationButtonType: Type, AppleAuthenticationButtonStyle: Style } = apple;
|
|
87
|
+
const buttonType = type === "sign-in" ? Type.SIGN_IN : type === "sign-up" ? Type.SIGN_UP : Type.CONTINUE;
|
|
88
|
+
const resolved = appearance === "auto" ? (mode === "dark" ? "white" : "black") : appearance;
|
|
89
|
+
const buttonStyle = resolved === "white" ? Style.WHITE : resolved === "white-outline" ? Style.WHITE_OUTLINE : Style.BLACK;
|
|
90
|
+
return (
|
|
91
|
+
<View testID={`${testID}-container`} pointerEvents={inactive ? "none" : "auto"} style={disabled ? { opacity: 0.5 } : undefined}>
|
|
92
|
+
<AppleAuthenticationButton
|
|
93
|
+
testID={testID}
|
|
94
|
+
buttonType={buttonType}
|
|
95
|
+
buttonStyle={buttonStyle}
|
|
96
|
+
cornerRadius={cornerRadius}
|
|
97
|
+
style={{ width: "100%", height }}
|
|
98
|
+
accessibilityState={{ disabled: inactive, busy }}
|
|
99
|
+
onPress={() => {
|
|
100
|
+
void press();
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
</View>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface AppleProviderOptions extends Omit<AppleSignInButtonProps, "apple" | "testID"> {
|
|
108
|
+
/** `expo-apple-authentication`, or `undefined` where it isn't installed. */
|
|
109
|
+
apple: AppleButtonModuleLike | null | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* The provider's `label`, used only by `AuthScreen`'s dev warning and a
|
|
112
|
+
* custom `social` slot. Apple's button draws and announces its own localized
|
|
113
|
+
* text. Default follows `type`: "Continue with Apple", "Sign in with Apple"
|
|
114
|
+
* or "Sign up with Apple".
|
|
115
|
+
*/
|
|
116
|
+
label?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const APPLE_LABELS = { continue: "Continue with Apple", "sign-in": "Sign in with Apple", "sign-up": "Sign up with Apple" } as const;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A `SocialAuthProvider` (id `"apple"`) that draws Apple's button, for
|
|
123
|
+
* `AuthScreen`'s `providers`. `null` off iOS or without the module.
|
|
124
|
+
*
|
|
125
|
+
* @stability Beta
|
|
126
|
+
*/
|
|
127
|
+
export function appleProvider({ apple, label, ...button }: AppleProviderOptions): SocialAuthProvider | null {
|
|
128
|
+
if (Platform.OS !== "ios" || !apple) return null;
|
|
129
|
+
return {
|
|
130
|
+
id: "apple",
|
|
131
|
+
label: label ?? APPLE_LABELS[button.type ?? "continue"],
|
|
132
|
+
onPress: button.onPress,
|
|
133
|
+
disabled: button.disabled,
|
|
134
|
+
render: ({ testID, disabled }) => <AppleSignInButton apple={apple} {...button} disabled={disabled} testID={testID} />,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* The form stays above the keyboard on small phones: with the app's
|
|
9
9
|
* `KeyboardScrollProvider` (react-native-keyboard-controller), else with
|
|
10
|
-
* `KeyboardAvoidingView`.
|
|
10
|
+
* `KeyboardAvoidingView`. With the provider's `toolbar` (`KeyboardToolbar`),
|
|
11
|
+
* a previous / next / done bar rides above the keyboard. In development, on
|
|
11
12
|
* iOS, it warns when a third-party provider is offered without Sign in with
|
|
12
|
-
* Apple (App Store Review Guideline 4.8 rejects that).
|
|
13
|
+
* Apple (App Store Review Guideline 4.8 rejects that). `appleProvider()`
|
|
14
|
+
* adds Apple's own button in one line.
|
|
13
15
|
*
|
|
14
16
|
* Slots: replace or drop (`null`) `branding`, `social`, `form` or `footer`;
|
|
15
17
|
* `slotProps` feeds a default part. Composing the primitives yourself is
|
|
@@ -30,7 +32,7 @@ import {
|
|
|
30
32
|
type SocialAuthProvider,
|
|
31
33
|
} from "./auth";
|
|
32
34
|
import { ScreenContainer } from "./screen-container";
|
|
33
|
-
import { useKeyboardScroll } from "./keyboard";
|
|
35
|
+
import { KEYBOARD_TOOLBAR_HEIGHT, useKeyboardScroll, useKeyboardToolbar } from "./keyboard";
|
|
34
36
|
|
|
35
37
|
/** The parts of an {@link AuthScreen} that `slots` and `slotProps` reach. */
|
|
36
38
|
export type AuthScreenSlotMap = {
|
|
@@ -43,8 +45,12 @@ export type AuthScreenSlotMap = {
|
|
|
43
45
|
export interface AuthScreenProps {
|
|
44
46
|
/** Logo, headline and subhead above everything else. */
|
|
45
47
|
branding?: AuthBrandingProps;
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Sign-in providers (Apple, Google…). None: no social row. A `null` or
|
|
50
|
+
* `false` entry is skipped, so a platform-only provider such as
|
|
51
|
+
* `appleProvider(...)` (null off iOS) goes in the list as is.
|
|
52
|
+
*/
|
|
53
|
+
providers?: Array<SocialAuthProvider | null | false | undefined>;
|
|
48
54
|
/** The email form. */
|
|
49
55
|
form: AuthFormProps;
|
|
50
56
|
/** Adds a "Forgot password?" link below the fields (password mode only). */
|
|
@@ -61,7 +67,7 @@ export interface AuthScreenProps {
|
|
|
61
67
|
|
|
62
68
|
export function AuthScreen({
|
|
63
69
|
branding,
|
|
64
|
-
providers,
|
|
70
|
+
providers: givenProviders,
|
|
65
71
|
form,
|
|
66
72
|
onForgotPassword,
|
|
67
73
|
footer,
|
|
@@ -69,11 +75,13 @@ export function AuthScreen({
|
|
|
69
75
|
slotProps = {},
|
|
70
76
|
testID = "auth-screen",
|
|
71
77
|
}: AuthScreenProps) {
|
|
78
|
+
const providers = givenProviders?.filter((p): p is SocialAuthProvider => !!p);
|
|
72
79
|
warnIfNoAppleSignIn(providers);
|
|
73
80
|
const forgot =
|
|
74
81
|
onForgotPassword && (form.mode ?? "password") === "password" ? <ForgotPasswordLink onPress={onForgotPassword} /> : null;
|
|
75
82
|
const formProps: AuthFormProps = { ...form, belowFields: form.belowFields ?? forgot, testID: form.testID ?? `${testID}-form` };
|
|
76
83
|
const KeyboardScroll = useKeyboardScroll();
|
|
84
|
+
const KeyboardToolbar = useKeyboardToolbar();
|
|
77
85
|
const content = (
|
|
78
86
|
<>
|
|
79
87
|
{branding ? renderSlot(AuthBranding, slots.branding, { ...branding, testID: branding.testID ?? `${testID}-branding` }, slotProps.branding) : null}
|
|
@@ -91,11 +99,12 @@ export function AuthScreen({
|
|
|
91
99
|
testID={`${testID}-keyboard`}
|
|
92
100
|
keyboardShouldPersistTaps="handled"
|
|
93
101
|
contentInsetAdjustmentBehavior="automatic"
|
|
94
|
-
bottomOffset={24}
|
|
102
|
+
bottomOffset={KeyboardToolbar ? 24 + KEYBOARD_TOOLBAR_HEIGHT : 24}
|
|
95
103
|
contentContainerStyle={{ flexGrow: 1, justifyContent: "center", gap: 24, paddingHorizontal: 24, paddingVertical: 32 }}
|
|
96
104
|
>
|
|
97
105
|
{content}
|
|
98
106
|
</KeyboardScroll>
|
|
107
|
+
{KeyboardToolbar ? <KeyboardToolbar /> : null}
|
|
99
108
|
</ScreenContainer>
|
|
100
109
|
);
|
|
101
110
|
}
|
|
@@ -121,7 +130,7 @@ function warnIfNoAppleSignIn(providers: SocialAuthProvider[] | undefined) {
|
|
|
121
130
|
if (warnedNoApple.has(ids)) return;
|
|
122
131
|
warnedNoApple.add(ids);
|
|
123
132
|
console.warn(
|
|
124
|
-
`[genesis] AuthScreen offers ${providers.map((p) => p.label).join(", ")} on iOS without Sign in with Apple. App Store Review Guideline 4.8 requires it; add
|
|
133
|
+
`[genesis] AuthScreen offers ${providers.map((p) => p.label).join(", ")} on iOS without Sign in with Apple. App Store Review Guideline 4.8 requires it; add appleProvider({ apple: AppleAuthentication, onPress }) (or any provider with id "apple"). If you did, expo-apple-authentication wasn't passed in.`,
|
|
125
134
|
);
|
|
126
135
|
}
|
|
127
136
|
|
package/src/layouts/auth.tsx
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @stability Beta
|
|
16
16
|
*/
|
|
17
|
-
import { useCallback, useRef, useState, type ReactNode } from "react";
|
|
17
|
+
import { Fragment, useCallback, useRef, useState, type ReactNode } from "react";
|
|
18
18
|
import { Pressable, Text, View } from "react-native";
|
|
19
19
|
import { NativeButton } from "../components/button";
|
|
20
20
|
import { NativeInput } from "../components/input";
|
|
@@ -92,6 +92,12 @@ export type SocialAuthProvider = {
|
|
|
92
92
|
onPress: () => void | Promise<void>;
|
|
93
93
|
/** When true, the button is disabled (e.g., loading). */
|
|
94
94
|
disabled?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Draw the provider's own button instead of the default outline button,
|
|
97
|
+
* for a provider whose brand rules require theirs (Apple: see
|
|
98
|
+
* `appleProvider`). Receives the testID the default would use.
|
|
99
|
+
*/
|
|
100
|
+
render?: (props: { testID: string; disabled?: boolean }) => ReactNode;
|
|
95
101
|
};
|
|
96
102
|
|
|
97
103
|
export interface SocialAuthRowProps {
|
|
@@ -116,24 +122,28 @@ export function SocialAuthRow({
|
|
|
116
122
|
return (
|
|
117
123
|
<View testID={testID} className={cn("gap-3", className)}>
|
|
118
124
|
<View className="gap-2">
|
|
119
|
-
{providers.map((p) =>
|
|
120
|
-
|
|
121
|
-
key={p.id}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
{providers.map((p) =>
|
|
126
|
+
p.render ? (
|
|
127
|
+
<Fragment key={p.id}>{p.render({ testID: `${testID}-${p.id}`, disabled: p.disabled })}</Fragment>
|
|
128
|
+
) : (
|
|
129
|
+
<NativeButton
|
|
130
|
+
key={p.id}
|
|
131
|
+
testID={`${testID}-${p.id}`}
|
|
132
|
+
variant="outline"
|
|
133
|
+
disabled={p.disabled}
|
|
134
|
+
onPress={() => {
|
|
135
|
+
void p.onPress();
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<View className="flex-row items-center gap-2">
|
|
139
|
+
{p.icon}
|
|
140
|
+
<Text className="text-sm font-medium text-foreground">
|
|
141
|
+
{p.label}
|
|
142
|
+
</Text>
|
|
143
|
+
</View>
|
|
144
|
+
</NativeButton>
|
|
145
|
+
),
|
|
146
|
+
)}
|
|
137
147
|
</View>
|
|
138
148
|
{separator !== null && separator !== undefined ? (
|
|
139
149
|
<View
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google sign-in for `AuthScreen` / `SocialAuthRow`: the provider entry,
|
|
3
|
+
* drawn as the row's outline button. Nothing here imports
|
|
4
|
+
* `@react-native-google-signin/google-signin`; sign in with
|
|
5
|
+
* `signInWithGoogle` from `@marktiderman/genesis-supabase/native`.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <AuthScreen providers={[appleProvider({ apple, onPress: onApple }), googleProvider({ onPress: onGoogle })]} … />
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Google's branding guidelines want its "G" mark on the button: pass it as
|
|
12
|
+
* `icon` (Genesis ships no Google artwork). On iOS, offer Sign in with Apple
|
|
13
|
+
* too (App Store Review Guideline 4.8); `AuthScreen` warns in development
|
|
14
|
+
* when it's missing.
|
|
15
|
+
*
|
|
16
|
+
* @stability Beta
|
|
17
|
+
*/
|
|
18
|
+
import type { ReactNode } from "react";
|
|
19
|
+
import type { SocialAuthProvider } from "./auth";
|
|
20
|
+
|
|
21
|
+
export interface GoogleProviderOptions {
|
|
22
|
+
/** Usually `() => signInWithGoogle(supabase, GoogleOneTapSignIn, { digest })`. */
|
|
23
|
+
onPress: () => void | Promise<void>;
|
|
24
|
+
/** Default "Continue with Google", Google's own wording. */
|
|
25
|
+
label?: string;
|
|
26
|
+
/** Google's "G" mark, as the app draws it. */
|
|
27
|
+
icon?: ReactNode;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/** `false` (or `null`) gives `null`, so a switched-off provider goes in the list as is. Default true. */
|
|
30
|
+
enabled?: boolean | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A `SocialAuthProvider` (id `"google"`) for `AuthScreen`'s `providers`, or
|
|
35
|
+
* `null` when `enabled` is false.
|
|
36
|
+
*
|
|
37
|
+
* @stability Beta
|
|
38
|
+
*/
|
|
39
|
+
export function googleProvider({ onPress, label = "Continue with Google", icon, disabled, enabled = true }: GoogleProviderOptions): SocialAuthProvider | null {
|
|
40
|
+
if (!enabled) return null;
|
|
41
|
+
return { id: "google", label, icon, onPress, disabled };
|
|
42
|
+
}
|