1.1.0 • Published 5 months ago

pager-view v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

šŸš€ pager-view

npm GitHub license npm version Downloads Runs with Expo


šŸ“Œ Features

āœ… Compatible with React 19 šŸŒ Supports React Native Web šŸ“ Dynamic Sizing šŸš€ Compatible with FlashList


šŸ“„ Installation & Usage

šŸ“¦ Quick Installation

Run one of the following commands to install the library:

npm install pager-view

Or using yarn:

yarn add pager-view

šŸŖ„ Quick Usage

āš›ļø Standard Example

import { Text, View } from "react-native";
import PagerView, { Pager } from "pager-view";

const Component = () => {
	const Header = () => <Text>PagerView</Text>;

	const Screen = () => (
		<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
			<Text style={{ color: "#f90" }}>Swipe āž”ļø</Text>
		</View>
	);

	return (
		<PagerView before={<Header />} headerColor="#2196f3">
			<Pager title="First Page" element={<Screen />} />
			<Pager index title="Second Page" element={<Text>Second page</Text>} />
			<Pager index={false} title="Third Page" element={<Text>Third page</Text>} />
		</PagerView>
	);
};

export default Component;

šŸŖ Using Hook

import { useState } from "react";
import { Text, View } from "react-native";
import PagerView, { Pager, useScroll, type ScrollRef } from "pager-view";

const Component = () => {
	const [state, setState] = useState<ScrollRef>({
		ref: null,
		width: 0,
	});

	const Screen = () => {
		const handleChange = useScroll(state.ref, state.width);

		return (
			<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
				<Text onPress={() => handleChange(2)} style={{ color: "#f90" }}>
					Swipe āž”ļø
				</Text>
			</View>
		);
	};

	return (
		<PagerView getRef={(ref, width) => setState({ ref, width })}>
			<Pager title="First Page" element={<Screen />} />
			<Pager index title="Second Page" element={<Text>Second page</Text>} />
			<Pager index={false} title="Third Page" element={<Text>Third page</Text>} />
		</PagerView>
	);
};

export default Component;

🌐 Web Configuration

⚔ Example with Vite

File: vite.config.ts

import { env } from "process";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";

const extensions = [".css", ".json", ".web.mjs", ".web.js", ".web.mts", ".web.ts", ".web.jsx", ".web.tsx", ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx"];

export default defineConfig({
	define: {
		__DEV__: JSON.stringify(env.NODE_ENV === "development"),
		global: "window",
		process: { env: { EXPO_OS: "web" } },
	},
	optimizeDeps: {
		esbuildOptions: {
			loader: { ".js": "jsx" },
			resolveExtensions: extensions,
		},
	},
	plugins: [react()],
	resolve: {
		alias: {
			"react-native": "react-native-web",
		},
		extensions,
	},
	server: { hmr: true, host: true, open: true },
});

ā–² Example with Next.js

File: next.config.mjs

const extensions = [".css", ".json", ".web.mjs", ".web.js", ".web.mts", ".web.ts", ".web.jsx", ".web.tsx", ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx"];

const nextConfig = {
	reactStrictMode: false,
	swcMinify: true,
	transpilePackages: ["react-native", "react-native-web"],
	webpack: config => {
		config.resolve.alias = {
			...(config.resolve.alias || {}),
			"react-native$": "react-native-web",
		};
		config.resolve.extensions = [...config.resolve.extensions, ...extensions];
		return config;
	},
};

export default nextConfig;

āš™ļø Available Props

šŸ“Ÿ PagerView

PropTypeDefaultDescription
beforereact-nodeundefinedOptional component rendered above the tab bar.
childrenreact-noderequiredMust contain Pager components defining the pages.
indicatorStylereact-styleundefinedStyling for the indicator.
getReffunctionundefinedGets the reference of the pages and their width
headerColorcolorundefinedIt must follow one of the following patterns: #, rgb, rgba, hsl, or hwb.
showIndicatorbooleantrueControls the visibility of the indicator.
stylereact-styleundefinedCustom styling for the component.
tabStylereact-styleundefinedStyling for the tabs.
titleStylereact-styleundefinedCustom styling for the tab text

🪟 Pager

PropTypeDefaultDescription
indexbooleanfalseDefines the default page. If multiple have this property, the last one is used.
titlestringrequiredTitle of the corresponding tab
elementreact-noderequiredReact component to be rendered

šŸ™Œ Support & Feedback

šŸ“¢ Found an issue or have suggestions? Open an issue on GitHub!

šŸ’» GitHub: @TheRonaldoStar 🐦 X/Twitter @TheRonaldoStar šŸ”—šŸ‘” Linkedin @TheRonaldoStar


1.1.0

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.8-canary

5 months ago

1.0.7

5 months ago

1.0.7-experimental

5 months ago

1.0.6

5 months ago

1.0.6-beta.3

5 months ago

1.0.6-beta.2

5 months ago

1.0.6-beta.1

5 months ago

1.0.6-beta

5 months ago

1.0.6-experimental

5 months ago

1.0.5

5 months ago

1.0.5-beta-1

6 months ago

1.0.5-beta-0

6 months ago

1.0.4

6 months ago

1.0.4-beta-3

6 months ago

1.0.4-beta-2

6 months ago

1.0.4-beta-1

6 months ago

1.0.4-beta-0

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

1.0.0-beta

6 months ago