react-native-magic-tab-bar 1.0.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/LICENSE +21 -0
- package/README.md +121 -0
- package/lib/module/MagicTabBar.js +130 -0
- package/lib/module/MagicTabBar.js.map +1 -0
- package/lib/module/MagicTabItem.js +96 -0
- package/lib/module/MagicTabItem.js.map +1 -0
- package/lib/module/MagicTabs.js +60 -0
- package/lib/module/MagicTabs.js.map +1 -0
- package/lib/module/defaultTabs.js +52 -0
- package/lib/module/defaultTabs.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/theme.js +16 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/MagicTabBar.d.ts +38 -0
- package/lib/typescript/MagicTabBar.d.ts.map +1 -0
- package/lib/typescript/MagicTabItem.d.ts +28 -0
- package/lib/typescript/MagicTabItem.d.ts.map +1 -0
- package/lib/typescript/MagicTabs.d.ts +49 -0
- package/lib/typescript/MagicTabs.d.ts.map +1 -0
- package/lib/typescript/defaultTabs.d.ts +10 -0
- package/lib/typescript/defaultTabs.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +10 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/theme.d.ts +4 -0
- package/lib/typescript/theme.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +48 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +91 -0
- package/src/MagicTabBar.tsx +181 -0
- package/src/MagicTabItem.tsx +123 -0
- package/src/MagicTabs.tsx +87 -0
- package/src/defaultTabs.tsx +55 -0
- package/src/index.tsx +15 -0
- package/src/theme.ts +15 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
import type { MagicTabConfig, MagicTabIconProps } from "./types";
|
|
4
|
+
|
|
5
|
+
type IoniconName = ComponentProps<typeof Ionicons>["name"];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds an icon renderer from a pair of Ionicons glyphs. The filled variant
|
|
9
|
+
* is shown for the active tab and the outline variant for inactive tabs.
|
|
10
|
+
*/
|
|
11
|
+
const ionicon =
|
|
12
|
+
(active: IoniconName, inactive: IoniconName) =>
|
|
13
|
+
({ focused, color, size }: MagicTabIconProps) => (
|
|
14
|
+
<Ionicons name={focused ? active : inactive} color={color} size={size} />
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The tabs used when `<MagicTabs />` is rendered without a `tabs` prop:
|
|
19
|
+
* Home, Explore, Notifications, Inbox and Profile, each with a matching Ionicon.
|
|
20
|
+
*
|
|
21
|
+
* Assumes the app has routes named `index` (`/`), `explore`, `notifications`,
|
|
22
|
+
* `inbox` and `profile`. Pass your own `tabs` to `<MagicTabs />` to override.
|
|
23
|
+
*/
|
|
24
|
+
export const defaultTabs: MagicTabConfig[] = [
|
|
25
|
+
{
|
|
26
|
+
name: "index",
|
|
27
|
+
href: "/",
|
|
28
|
+
label: "Home",
|
|
29
|
+
icon: ionicon("home", "home-outline"),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "explore",
|
|
33
|
+
href: "/explore",
|
|
34
|
+
label: "Explore",
|
|
35
|
+
icon: ionicon("compass", "compass-outline"),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "notifications",
|
|
39
|
+
href: "/notifications",
|
|
40
|
+
label: "Notifications",
|
|
41
|
+
icon: ionicon("notifications", "notifications-outline"),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "inbox",
|
|
45
|
+
href: "/inbox",
|
|
46
|
+
label: "Inbox",
|
|
47
|
+
icon: ionicon("chatbubble-sharp", "chatbubble-outline"),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "profile",
|
|
51
|
+
href: "/profile",
|
|
52
|
+
label: "Profile",
|
|
53
|
+
icon: ionicon("person", "person-outline"),
|
|
54
|
+
},
|
|
55
|
+
];
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { MagicTabs } from './MagicTabs';
|
|
2
|
+
export { MagicTabBar } from './MagicTabBar';
|
|
3
|
+
export { MagicTabItem } from './MagicTabItem';
|
|
4
|
+
export { defaultTabs } from './defaultTabs';
|
|
5
|
+
export { defaultTheme } from './theme';
|
|
6
|
+
|
|
7
|
+
export type { MagicTabsProps } from './MagicTabs';
|
|
8
|
+
export type { MagicTabBarProps } from './MagicTabBar';
|
|
9
|
+
export type { MagicTabItemProps } from './MagicTabItem';
|
|
10
|
+
export type {
|
|
11
|
+
MagicTabConfig,
|
|
12
|
+
MagicTabIconProps,
|
|
13
|
+
MagicTabBarTheme,
|
|
14
|
+
MagicTabBarVariant,
|
|
15
|
+
} from './types';
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MagicTabBarTheme } from './types';
|
|
2
|
+
|
|
3
|
+
/** Default dark, floating-pill theme. */
|
|
4
|
+
export const defaultTheme: MagicTabBarTheme = {
|
|
5
|
+
barColor: 'rgba(38, 38, 40, 0.94)',
|
|
6
|
+
activePillColor: 'rgba(120, 120, 124, 0.55)',
|
|
7
|
+
activeColor: '#FFFFFF',
|
|
8
|
+
inactiveColor: '#FFFFFF',
|
|
9
|
+
iconSize: 22,
|
|
10
|
+
fontSize: 12,
|
|
11
|
+
height: 56,
|
|
12
|
+
radius: 28,
|
|
13
|
+
horizontalMargin: 14,
|
|
14
|
+
bottomInset: 10,
|
|
15
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { Href } from 'expo-router';
|
|
3
|
+
|
|
4
|
+
/** Props passed to each tab's `icon` render function. */
|
|
5
|
+
export interface MagicTabIconProps {
|
|
6
|
+
/** Whether this tab is the active one. */
|
|
7
|
+
focused: boolean;
|
|
8
|
+
/** Resolved color for the icon (active or inactive color from the theme). */
|
|
9
|
+
color: string;
|
|
10
|
+
/** Icon size in points (from the theme). */
|
|
11
|
+
size: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Configuration for a single tab. */
|
|
15
|
+
export interface MagicTabConfig {
|
|
16
|
+
/** Route name — must match the file in the `app/` directory (e.g. `"index"`, `"search"`). */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Destination href, e.g. `"/"` or `"/search"`. */
|
|
19
|
+
href: Href;
|
|
20
|
+
/** Optional text label rendered next to the icon while the tab is active. */
|
|
21
|
+
label?: string;
|
|
22
|
+
/** Renders the tab's icon. */
|
|
23
|
+
icon: (props: MagicTabIconProps) => ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Visual configuration for the tab bar. */
|
|
27
|
+
export interface MagicTabBarTheme {
|
|
28
|
+
/** Background color of the bar (ignored when `renderBackground` is provided). */
|
|
29
|
+
barColor: string;
|
|
30
|
+
/** Background color of the pill behind the active tab. */
|
|
31
|
+
activePillColor: string;
|
|
32
|
+
/** Icon/label color for the active tab. */
|
|
33
|
+
activeColor: string;
|
|
34
|
+
/** Icon color for inactive tabs. */
|
|
35
|
+
inactiveColor: string;
|
|
36
|
+
/** Icon size in points. */
|
|
37
|
+
iconSize: number;
|
|
38
|
+
/** Font size of the active tab's label, in points. */
|
|
39
|
+
fontSize: number;
|
|
40
|
+
/** Height of the bar. */
|
|
41
|
+
height: number;
|
|
42
|
+
/** Corner radius of the bar and the active pill. */
|
|
43
|
+
radius: number;
|
|
44
|
+
/** Horizontal margin between the bar and the screen edges. */
|
|
45
|
+
horizontalMargin: number;
|
|
46
|
+
/** Extra space below the bar, added on top of the safe-area inset. */
|
|
47
|
+
bottomInset: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** How the bar is positioned relative to screen content. */
|
|
51
|
+
export type MagicTabBarVariant = 'floating' | 'docked';
|