@stackflow/plugin-basic-ui 0.20.0 → 0.20.2-alpha.3

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useActions } from "@stackflow/react";
4
4
  import { assignInlineVars } from "@vanilla-extract/dynamic";
5
- import React, { useRef } from "react";
5
+ import React, { createContext, useContext, useMemo, useRef } from "react";
6
6
 
7
7
  import { useGlobalOptions } from "../basicUIPlugin";
8
8
  import {
@@ -19,11 +19,19 @@ import { compactMap } from "../utils";
19
19
  import AppBar from "./AppBar";
20
20
  import * as css from "./AppScreen.css";
21
21
 
22
- type AppScreenProps = Partial<
22
+ export type AppScreenContext = {
23
+ scroll: (args: { top: number }) => void;
24
+ };
25
+ const Context = createContext<AppScreenContext>(null as any);
26
+
27
+ export function useAppScreen() {
28
+ return useContext(Context);
29
+ }
30
+
31
+ export type AppScreenProps = Partial<
23
32
  Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
24
33
  > & {
25
34
  appBar?: Omit<PropOf<typeof AppBar>, "theme" | "ref" | "key">;
26
-
27
35
  preventSwipeBack?: boolean;
28
36
  children: React.ReactNode;
29
37
  };
@@ -89,52 +97,66 @@ const AppScreen: React.FC<AppScreenProps> = ({
89
97
  };
90
98
 
91
99
  return (
92
- <div
93
- ref={appScreenRef}
94
- className={css.appScreen({
95
- transitionState:
96
- transitionState === "enter-done" || transitionState === "exit-done"
97
- ? transitionState
98
- : lazyTransitionState,
99
- })}
100
- style={assignInlineVars(
101
- compactMap({
102
- [globalVars.backgroundColor]: backgroundColor,
103
- [globalVars.dimBackgroundColor]: dimBackgroundColor,
104
- [globalVars.appBar.height]: appBar?.height,
105
- [globalVars.appBar.heightTransitionDuration]:
106
- appBar?.heightTransitionDuration,
107
- [css.vars.zIndexes.dim]: `${zIndexDim}`,
108
- [css.vars.zIndexes.paper]: `${zIndexPaper}`,
109
- [css.vars.zIndexes.edge]: `${zIndexEdge}`,
110
- [css.vars.zIndexes.appBar]: `${zIndexAppBar}`,
111
- [css.vars.transitionDuration]:
112
- transitionState === "enter-active" ||
113
- transitionState === "exit-active"
114
- ? `var(--stackflow-transition-duration)`
115
- : "0ms",
100
+ <Context.Provider
101
+ value={useMemo(
102
+ () => ({
103
+ scroll({ top }) {
104
+ paperRef?.current?.scroll({
105
+ top,
106
+ behavior: "smooth",
107
+ });
108
+ },
116
109
  }),
110
+ [paperRef],
117
111
  )}
118
112
  >
119
- <div className={css.dim} ref={dimRef} />
120
113
  <div
121
- key={activity?.id}
122
- className={css.paper({
123
- hasAppBar,
114
+ ref={appScreenRef}
115
+ className={css.appScreen({
116
+ transitionState:
117
+ transitionState === "enter-done" || transitionState === "exit-done"
118
+ ? transitionState
119
+ : lazyTransitionState,
124
120
  })}
125
- ref={paperRef}
121
+ style={assignInlineVars(
122
+ compactMap({
123
+ [globalVars.backgroundColor]: backgroundColor,
124
+ [globalVars.dimBackgroundColor]: dimBackgroundColor,
125
+ [globalVars.appBar.height]: appBar?.height,
126
+ [globalVars.appBar.heightTransitionDuration]:
127
+ appBar?.heightTransitionDuration,
128
+ [css.vars.zIndexes.dim]: `${zIndexDim}`,
129
+ [css.vars.zIndexes.paper]: `${zIndexPaper}`,
130
+ [css.vars.zIndexes.edge]: `${zIndexEdge}`,
131
+ [css.vars.zIndexes.appBar]: `${zIndexAppBar}`,
132
+ [css.vars.transitionDuration]:
133
+ transitionState === "enter-active" ||
134
+ transitionState === "exit-active"
135
+ ? `var(--stackflow-transition-duration)`
136
+ : "0ms",
137
+ }),
138
+ )}
126
139
  >
127
- {children}
128
- </div>
129
- {!activity?.isRoot &&
130
- globalOptions.theme === "cupertino" &&
131
- !preventSwipeBack && (
132
- <div className={css.edge({ hasAppBar })} ref={edgeRef} />
140
+ <div className={css.dim} ref={dimRef} />
141
+ <div
142
+ key={activity?.id}
143
+ className={css.paper({
144
+ hasAppBar,
145
+ })}
146
+ ref={paperRef}
147
+ >
148
+ {children}
149
+ </div>
150
+ {!activity?.isRoot &&
151
+ globalOptions.theme === "cupertino" &&
152
+ !preventSwipeBack && (
153
+ <div className={css.edge({ hasAppBar })} ref={edgeRef} />
154
+ )}
155
+ {appBar && (
156
+ <AppBar {...appBar} ref={appBarRef} onTopClick={onAppBarTopClick} />
133
157
  )}
134
- {appBar && (
135
- <AppBar {...appBar} ref={appBarRef} onTopClick={onAppBarTopClick} />
136
- )}
137
- </div>
158
+ </div>
159
+ </Context.Provider>
138
160
  );
139
161
  };
140
162
 
@@ -20,7 +20,7 @@ export const enterActive = style({});
20
20
  export const enterDone = style({});
21
21
  export const exitActive = style({});
22
22
  export const exitDone = style({
23
- transform: "translateX(100%)",
23
+ transform: "translate3d(100%, 0, 0)",
24
24
  });
25
25
 
26
26
  export const container = recipe({
@@ -62,15 +62,16 @@ export const paper = style([
62
62
  backgroundColor: globalVars.backgroundColor,
63
63
  width: "100%",
64
64
  borderRadius: `${globalVars.bottomSheet.borderRadius} ${globalVars.bottomSheet.borderRadius} 0 0`,
65
- transform: "translateY(100%)",
65
+ willChange: "transform, opacity",
66
+ transform: "translate3d(0, 100%, 0)",
66
67
  opacity: 0,
67
68
  selectors: {
68
69
  [`${enterActive} &, ${enterDone} &`]: {
69
- transform: "translateY(0)",
70
+ transform: "translate3d(0, 0, 0)",
70
71
  opacity: 1,
71
72
  },
72
73
  [`${exitActive} &, ${exitDone} &`]: {
73
- transform: "translateY(100%)",
74
+ transform: "translate3d(0, 100%, 0)",
74
75
  opacity: 0,
75
76
  },
76
77
  },
@@ -10,7 +10,7 @@ import { globalVars } from "../theme.css";
10
10
  import { compactMap } from "../utils";
11
11
  import * as css from "./BottomSheet.css";
12
12
 
13
- type BottomSheetProps = Partial<
13
+ export type BottomSheetProps = Partial<
14
14
  Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
15
15
  > &
16
16
  Partial<GlobalVars["bottomSheet"]> & {
@@ -20,7 +20,7 @@ export const enterActive = style({});
20
20
  export const enterDone = style({});
21
21
  export const exitActive = style({});
22
22
  export const exitDone = style({
23
- transform: "translateX(100%)",
23
+ transform: "translate3d(100%, 0, 0)",
24
24
  });
25
25
 
26
26
  export const container = recipe({
@@ -66,6 +66,7 @@ export const paper = style([
66
66
  boxShadow:
67
67
  "0px 0.625rem 2.375rem rgba(0, 0, 0, 0.15), 0px .5625rem 2.875rem rgba(0, 0, 0, 0.12), 0px .3125rem .9375rem rgba(0, 0, 0, 0.1)",
68
68
  borderRadius: globalVars.modal.borderRadius,
69
+ willChange: "transform, opacity",
69
70
  transform: "scale(1.1)",
70
71
  opacity: 0,
71
72
  selectors: {
@@ -10,7 +10,7 @@ import { globalVars } from "../theme.css";
10
10
  import { compactMap } from "../utils";
11
11
  import * as css from "./Modal.css";
12
12
 
13
- type ModalProps = Partial<
13
+ export type ModalProps = Partial<
14
14
  Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
15
15
  > &
16
16
  Partial<GlobalVars["modal"]> & {
@@ -22,8 +22,8 @@ export function useStyleEffectOffset({
22
22
  ? ({ activityTransitionState, refs }) => {
23
23
  const transform =
24
24
  theme === "cupertino"
25
- ? `translateX(-${OFFSET_PX_CUPERTINO / 16}rem)`
26
- : `translateY(-${OFFSET_PX_ANDROID / 16}rem)`;
25
+ ? `translate3d(-${OFFSET_PX_CUPERTINO / 16}rem, 0, 0)`
26
+ : `translate3d(0, -${OFFSET_PX_ANDROID / 16}rem, 0)`;
27
27
 
28
28
  const cleanup = () => {
29
29
  requestNextFrame(() => {
@@ -72,7 +72,7 @@ export function useStyleEffectSwipeBack({
72
72
  $dim.style.transition = "0s";
73
73
 
74
74
  $paper.style.overflowY = "hidden";
75
- $paper.style.transform = `translateX(${dx}px)`;
75
+ $paper.style.transform = `translate3d(${dx}px, 0, 0)`;
76
76
  $paper.style.transition = "0s";
77
77
 
78
78
  refs.forEach((ref) => {
@@ -80,9 +80,9 @@ export function useStyleEffectSwipeBack({
80
80
  return;
81
81
  }
82
82
 
83
- ref.current.style.transform = `translateX(${
83
+ ref.current.style.transform = `translate3d(${
84
84
  -1 * (1 - p) * OFFSET_PX_CUPERTINO
85
- }px)`;
85
+ }px, 0, 0)`;
86
86
  ref.current.style.transition = "0s";
87
87
 
88
88
  if (ref.current.parentElement?.style.display === "none") {
@@ -112,9 +112,9 @@ export function useStyleEffectSwipeBack({
112
112
  }
113
113
 
114
114
  ref.current.style.transition = `var(--stackflow-transition-duration)`;
115
- ref.current.style.transform = `translateX(${
115
+ ref.current.style.transform = `translate3d(${
116
116
  swiped ? "0" : `-${OFFSET_PX_CUPERTINO / 16}rem`
117
- })`;
117
+ }, 0, 0)`;
118
118
  });
119
119
 
120
120
  const _cachedRefs = [...cachedRefs];
package/src/index.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  export { basicUIPlugin } from "./basicUIPlugin";
2
- export { default as AppScreen } from "./components/AppScreen";
3
- export { default as BottomSheet } from "./components/BottomSheet";
4
- export { default as Modal } from "./components/Modal";
2
+ export {
3
+ default as AppScreen,
4
+ AppScreenContext,
5
+ AppScreenProps,
6
+ useAppScreen,
7
+ } from "./components/AppScreen";
8
+ export {
9
+ default as BottomSheet,
10
+ BottomSheetProps,
11
+ } from "./components/BottomSheet";
12
+ export { default as Modal, ModalProps } from "./components/Modal";
5
13
  export { globalVars as cssVars } from "./theme.css";