Page MenuHomePhabricator

D12963.id43261.diff
No OneTemporary

D12963.id43261.diff

diff --git a/native/components/nux-tips-context.react.js b/native/components/nux-tips-context.react.js
new file mode 100644
--- /dev/null
+++ b/native/components/nux-tips-context.react.js
@@ -0,0 +1,72 @@
+// @flow
+
+import * as React from 'react';
+
+import { values } from 'lib/utils/objects.js';
+
+const nuxTip = Object.freeze({
+ MUTED: 'muted',
+ COMMUNITY_DRAWER: 'community_drawer',
+});
+
+type NUXTip = $Values<typeof nuxTip>;
+
+type TipProps = {
+ +x: ?number,
+ +y: ?number,
+ +width: ?number,
+ +height: ?number,
+ +pageX: ?number,
+ +pageY: ?number,
+};
+
+export type NUXTipsContextType = {
+ +registerTipButton: (type: NUXTip, tipProps: TipProps) => void,
+ +getTipsProps: () => ?{ [type: NUXTip]: TipProps },
+};
+
+const NUXTipsContext: React.Context<?NUXTipsContextType> =
+ React.createContext<?NUXTipsContextType>();
+
+type Props = {
+ +children: React.Node,
+};
+
+function NUXTipsContextProvider(props: Props): React.Node {
+ const { children } = props;
+
+ const tipsProps = React.useRef<{ [tip: NUXTip]: TipProps }>({});
+
+ const registerTipButton = React.useCallback(
+ (type: NUXTip, tipProps: TipProps) => {
+ tipsProps.current[type] = {
+ ...tipsProps.current[type],
+ ...tipProps,
+ };
+ },
+ [],
+ );
+
+ const getTipsProps = React.useCallback(() => {
+ for (const type of values(nuxTip)) {
+ if (!tipsProps.current[type]) {
+ return null;
+ }
+ }
+ return tipsProps.current;
+ }, []);
+
+ const value = React.useMemo(
+ () => ({
+ registerTipButton,
+ getTipsProps,
+ }),
+ [getTipsProps, registerTipButton],
+ );
+
+ return (
+ <NUXTipsContext.Provider value={value}>{children}</NUXTipsContext.Provider>
+ );
+}
+
+export { NUXTipsContext, NUXTipsContextProvider, nuxTip };
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -54,6 +54,7 @@
import BackgroundIdentityLoginHandler from './components/background-identity-login-handler.react.js';
import ConnectFarcasterAlertHandler from './components/connect-farcaster-alert-handler.react.js';
import { FeatureFlagsProvider } from './components/feature-flags-provider.react.js';
+import { NUXTipsContextProvider } from './components/nux-tips-context.react.js';
import PersistedStateGate from './components/persisted-state-gate.js';
import ReportHandler from './components/report-handler.react.js';
import VersionSupportedChecker from './components/version-supported.react.js';
@@ -303,7 +304,9 @@
<ChatContextProvider>
<DeepLinksContextProvider>
<ChatMentionContextProvider>
- <RootNavigator />
+ <NUXTipsContextProvider>
+ <RootNavigator />
+ </NUXTipsContextProvider>
</ChatMentionContextProvider>
</DeepLinksContextProvider>
</ChatContextProvider>

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 12:53 AM (19 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559237
Default Alt Text
D12963.id43261.diff (2 KB)

Event Timeline