@reown/appkit-react-native 0.0.0-chore-qr-borders-20251104183806 → 0.0.0-chore-use-theme-hook-20251105193739

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.
Files changed (72) hide show
  1. package/lib/commonjs/hooks/useAccount.js +4 -4
  2. package/lib/commonjs/hooks/useAccount.js.map +1 -1
  3. package/lib/commonjs/hooks/useAppKit.js +41 -9
  4. package/lib/commonjs/hooks/useAppKit.js.map +1 -1
  5. package/lib/commonjs/hooks/useAppKitContext.js +46 -0
  6. package/lib/commonjs/hooks/useAppKitContext.js.map +1 -0
  7. package/lib/commonjs/hooks/useAppKitEvents.js +64 -4
  8. package/lib/commonjs/hooks/useAppKitEvents.js.map +1 -1
  9. package/lib/commonjs/hooks/useAppKitLogs.js +2 -8
  10. package/lib/commonjs/hooks/useAppKitLogs.js.map +1 -1
  11. package/lib/commonjs/hooks/useAppKitState.js +35 -2
  12. package/lib/commonjs/hooks/useAppKitState.js.map +1 -1
  13. package/lib/commonjs/hooks/useAppKitTheme.js +74 -0
  14. package/lib/commonjs/hooks/useAppKitTheme.js.map +1 -0
  15. package/lib/commonjs/hooks/useProvider.js +3 -4
  16. package/lib/commonjs/hooks/useProvider.js.map +1 -1
  17. package/lib/commonjs/hooks/useWalletInfo.js +33 -2
  18. package/lib/commonjs/hooks/useWalletInfo.js.map +1 -1
  19. package/lib/commonjs/index.js +7 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/module/hooks/useAccount.js +4 -4
  22. package/lib/module/hooks/useAccount.js.map +1 -1
  23. package/lib/module/hooks/useAppKit.js +43 -10
  24. package/lib/module/hooks/useAppKit.js.map +1 -1
  25. package/lib/module/hooks/useAppKitContext.js +42 -0
  26. package/lib/module/hooks/useAppKitContext.js.map +1 -0
  27. package/lib/module/hooks/useAppKitEvents.js +65 -4
  28. package/lib/module/hooks/useAppKitEvents.js.map +1 -1
  29. package/lib/module/hooks/useAppKitLogs.js +3 -9
  30. package/lib/module/hooks/useAppKitLogs.js.map +1 -1
  31. package/lib/module/hooks/useAppKitState.js +36 -2
  32. package/lib/module/hooks/useAppKitState.js.map +1 -1
  33. package/lib/module/hooks/useAppKitTheme.js +71 -0
  34. package/lib/module/hooks/useAppKitTheme.js.map +1 -0
  35. package/lib/module/hooks/useProvider.js +3 -4
  36. package/lib/module/hooks/useProvider.js.map +1 -1
  37. package/lib/module/hooks/useWalletInfo.js +34 -2
  38. package/lib/module/hooks/useWalletInfo.js.map +1 -1
  39. package/lib/module/index.js +1 -0
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/typescript/AppKitContext.d.ts +1 -1
  42. package/lib/typescript/AppKitContext.d.ts.map +1 -1
  43. package/lib/typescript/hooks/useAccount.d.ts.map +1 -1
  44. package/lib/typescript/hooks/useAppKit.d.ts +42 -0
  45. package/lib/typescript/hooks/useAppKit.d.ts.map +1 -1
  46. package/lib/typescript/hooks/useAppKitContext.d.ts +27 -0
  47. package/lib/typescript/hooks/useAppKitContext.d.ts.map +1 -0
  48. package/lib/typescript/hooks/useAppKitEvents.d.ts +59 -0
  49. package/lib/typescript/hooks/useAppKitEvents.d.ts.map +1 -1
  50. package/lib/typescript/hooks/useAppKitLogs.d.ts.map +1 -1
  51. package/lib/typescript/hooks/useAppKitState.d.ts +32 -0
  52. package/lib/typescript/hooks/useAppKitState.d.ts.map +1 -1
  53. package/lib/typescript/hooks/useAppKitTheme.d.ts +59 -0
  54. package/lib/typescript/hooks/useAppKitTheme.d.ts.map +1 -0
  55. package/lib/typescript/hooks/useProvider.d.ts +1 -4
  56. package/lib/typescript/hooks/useProvider.d.ts.map +1 -1
  57. package/lib/typescript/hooks/useWalletInfo.d.ts +31 -0
  58. package/lib/typescript/hooks/useWalletInfo.d.ts.map +1 -1
  59. package/lib/typescript/index.d.ts +1 -0
  60. package/lib/typescript/index.d.ts.map +1 -1
  61. package/package.json +5 -4
  62. package/src/AppKitContext.tsx +1 -1
  63. package/src/hooks/useAccount.ts +5 -3
  64. package/src/hooks/useAppKit.ts +45 -12
  65. package/src/hooks/useAppKitContext.ts +43 -0
  66. package/src/hooks/useAppKitEvents.ts +63 -3
  67. package/src/hooks/useAppKitLogs.ts +3 -11
  68. package/src/hooks/useAppKitState.ts +35 -2
  69. package/src/hooks/useAppKitTheme.ts +81 -0
  70. package/src/hooks/useProvider.ts +3 -4
  71. package/src/hooks/useWalletInfo.ts +33 -2
  72. package/src/index.ts +1 -0
@@ -0,0 +1,81 @@
1
+ import { useMemo } from 'react';
2
+ import { useSnapshot } from 'valtio';
3
+ import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-native';
4
+ import { ThemeController } from '@reown/appkit-core-react-native';
5
+ import { useAppKitContext } from './useAppKitContext';
6
+
7
+ /**
8
+ * Interface representing the result of the useAppKitTheme hook
9
+ */
10
+ export interface UseAppKitThemeReturn {
11
+ /** The current theme mode ('dark' or 'light'), or undefined if using system default */
12
+ themeMode: ThemeMode | undefined;
13
+ /** The current theme variables, currently only supports 'accent' color */
14
+ themeVariables: ThemeVariables | undefined;
15
+ /** Function to set the theme mode */
16
+ setThemeMode: (themeMode: ThemeMode | undefined) => void;
17
+ /** Function to set theme variables */
18
+ setThemeVariables: (themeVariables: ThemeVariables | undefined) => void;
19
+ }
20
+
21
+ /**
22
+ * Hook to control the visual appearance of the AppKit modal
23
+ *
24
+ * @remarks
25
+ * This hook provides access to the theme mode and theme variables, allowing you to
26
+ * customize the modal's appearance. Use this hook when you need to implement dark/light
27
+ * mode or match the modal's appearance with your application's theme.
28
+ *
29
+ * Currently, the only supported theme variable is `accent`, which controls the primary
30
+ * accent color used throughout the modal interface.
31
+ *
32
+ * @returns {UseAppKitThemeReturn} An object containing:
33
+ * - `themeMode`: The current theme mode ('dark' or 'light')
34
+ * - `themeVariables`: The current theme variables (only 'accent' is supported)
35
+ * - `setThemeMode`: Function to change the theme mode
36
+ * - `setThemeVariables`: Function to update theme variables
37
+ *
38
+ * @throws {Error} If used outside of an AppKitProvider
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { useAppKitTheme } from '@reown/appkit-react-native';
43
+ *
44
+ * function MyComponent() {
45
+ * const { themeMode, themeVariables, setThemeMode, setThemeVariables } = useAppKitTheme();
46
+ *
47
+ * // Set theme to dark mode
48
+ * setThemeMode('dark');
49
+ *
50
+ * // Customize the accent color
51
+ * setThemeVariables({
52
+ * accent: '#00BB7F'
53
+ * });
54
+ *
55
+ * return (
56
+ * <View>
57
+ * <Text>Current theme: {themeMode}</Text>
58
+ * <Text>Accent color: {themeVariables?.accent}</Text>
59
+ * </View>
60
+ * );
61
+ * }
62
+ * ```
63
+ */
64
+ export function useAppKitTheme(): UseAppKitThemeReturn {
65
+ useAppKitContext();
66
+ const { themeMode, themeVariables } = useSnapshot(ThemeController.state);
67
+
68
+ const stableFunctions = useMemo(
69
+ () => ({
70
+ setThemeMode: ThemeController.setThemeMode.bind(ThemeController),
71
+ setThemeVariables: ThemeController.setThemeVariables.bind(ThemeController)
72
+ }),
73
+ []
74
+ );
75
+
76
+ return {
77
+ themeMode,
78
+ themeVariables,
79
+ ...stableFunctions
80
+ };
81
+ }
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
3
3
  import { useSnapshot } from 'valtio';
4
4
  import { ConnectionsController, LogController } from '@reown/appkit-core-react-native';
5
5
  import type { Provider, ChainNamespace } from '@reown/appkit-common-react-native';
6
+ import { useAppKitContext } from './useAppKitContext';
6
7
 
7
8
  /**
8
9
  * Interface representing the result of the useProvider hook
@@ -29,14 +30,12 @@ interface ProviderResult {
29
30
  *
30
31
  * if (provider) {
31
32
  * // Use the provider for blockchain operations
32
- * const balance = await provider.request({
33
- * method: 'eth_getBalance',
34
- * params: [address, 'latest']
35
- * });
33
+ * const balance = await provider.request({...});
36
34
  * }
37
35
  * ```
38
36
  */
39
37
  export function useProvider(): ProviderResult {
38
+ useAppKitContext();
40
39
  const { connection } = useSnapshot(ConnectionsController.state);
41
40
 
42
41
  const returnValue = useMemo(() => {
@@ -1,10 +1,41 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useSnapshot } from 'valtio';
3
3
  import { ConnectionsController } from '@reown/appkit-core-react-native';
4
- import { useAppKit } from './useAppKit';
4
+ import { useAppKitContext } from './useAppKitContext';
5
5
 
6
+ /**
7
+ * Hook to access information about the currently connected wallet
8
+ *
9
+ * @remarks
10
+ * This hook provides access to metadata about the connected wallet, such as its name,
11
+ * icon, and other identifying information. It automatically subscribes to wallet info
12
+ * changes via valtio.
13
+ *
14
+ * @returns An object containing:
15
+ * - `walletInfo`: Metadata about the currently connected wallet (name, icon, etc.)
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function MyComponent() {
20
+ * const { walletInfo } = useWalletInfo();
21
+ *
22
+ * return (
23
+ * <View>
24
+ * {walletInfo && (
25
+ * <>
26
+ * <Image source={{ uri: walletInfo.icon }} />
27
+ * <Text>{walletInfo.name}</Text>
28
+ * </>
29
+ * )}
30
+ * </View>
31
+ * );
32
+ * }
33
+ * ```
34
+ *
35
+ * @throws {Error} If used outside of an AppKitProvider
36
+ */
6
37
  export function useWalletInfo() {
7
- useAppKit(); // Use the hook for checks
38
+ useAppKitContext();
8
39
  const { walletInfo: walletInfoSnapshot } = useSnapshot(ConnectionsController.state);
9
40
 
10
41
  const walletInfo = useMemo(() => ({ walletInfo: walletInfoSnapshot }), [walletInfoSnapshot]);
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ export type { AppKitConfig } from './types';
32
32
  export { useAppKit } from './hooks/useAppKit';
33
33
  export { useProvider } from './hooks/useProvider';
34
34
  export { useAccount, type Account as UseAccountReturn } from './hooks/useAccount';
35
+ export { useAppKitTheme, type UseAppKitThemeReturn } from './hooks/useAppKitTheme';
35
36
  export { useWalletInfo } from './hooks/useWalletInfo';
36
37
  export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents';
37
38
  export { useAppKitState } from './hooks/useAppKitState';