# React Native Tab View
[![Build Status][build-badge]][build]
[![Version][version-badge]][package]
[![MIT License][license-badge]][license]
A cross-platform Tab View component for React Native.
This is a JavaScript-only implementation of swipeable tab views. It's super customizable, allowing you to do things like coverflow.
- [Run the example app to see it in action](https://expo.io/@satya164/react-native-tab-view-demos).
- Checkout the [example/](https://github.com/react-native-community/react-native-tab-view/tree/master/example) folder for source code.
## Features
- Smooth animations and gestures
- Scrollable tabs
- Supports both top and bottom tab bars
- Follows Material Design spec
- Highly customizable
- Fully typed with [Flow](https://flow.org/)
## Demo
<a href="https://raw.githubusercontent.com/satya164/react-native-tab-view/master/demo/demo.mp4"><img src="https://raw.githubusercontent.com/satya164/react-native-tab-view/master/demo/demo.gif" width="360"></a>
## Installation
```sh
yarn add react-native-tab-view
```
## Quick Start
```js
import * as React from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import { TabView, TabBar, SceneMap } from 'react-native-tab-view';
const FirstRoute = () => (
<View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
);
const SecondRoute = () => (
<View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
);
export default class TabViewExample extends React.Component {
state = {
index: 0,
routes: [
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
],
};
render() {
return (
<TabView
navigationState={this.state}
renderScene={SceneMap({
first: FirstRoute,
second: SecondRoute,
})}
onIndexChange={index => this.setState({ index })}
initialLayout={{ width: Dimensions.get('window').width }}
/>
);
}
}
const styles = StyleSheet.create({
scene: {
flex: 1,
},
});
```
[Try this example on Snack](https://snack.expo.io/@satya164/react-native-tab-view-quick-start)
## More examples on Snack
- [Custom Tab Bar](https://snack.expo.io/@satya164/react-native-tab-view-custom-tabbar)
- [Lazy Load](https://snack.expo.io/@satya164/react-native-tab-view-lazy-load)
## Integration with React Navigation
React Navigation integration can be achieved by the [react-navigation-tabs](https://github.com/react-navigation/react-navigation-tabs) package. Note that while it's easier to use, it is not as flexible as using the library directly.
## API reference
The package exports a `TabView` component which is the one you'd use to render the tab view, a `TabBar` component which is the default tab bar implementation, as well as several pager components for more fine-grained control.
In a trivial app, you'd mostly only use `TabView` and `TabBar`.
### `<TabView />`
Container component responsible for rendering and managing tabs.
#### Example
```js
<TabView
navigationState={this.state}
onIndexChange={index => this.setState({ index })}
renderScene={SceneMap({
first: FirstRoute,
second: SecondRoute,
})}
/>
```
#### Props
- `navigationState` (required): the current navigation state, should contain a `routes` array containing the list of tabs, and an `index` property representing the current tab.
- `onIndexChange` (required): callback for when the current tab index changes, should update the navigation state.
- `renderScene` (required): callback which returns a React Element to use as the scene for a tab.
- `renderTabBar`: callback which returns a custom React Element to use as the tab bar.
- `renderPager`: callback which returns a custom React Element to handle swipe gesture and animation.
- `canJumpToTab`: callback which returns a boolean indicating whether jumping to the tab is allowed.
- `initialLayout`: object containing the initial `height` and `width`, can be passed to prevent the one frame delay in rendering.
- `tabBarPosition`: position of the tab bar, `'top'` or `'bottom'`. Defaults to `'top'`.
Any other props are passed to the underlying pager.
### `<TabBar />`
Material design themed tab bar. To pass props to the tab bar, you'd need to use the `renderTabBar` prop of `TabView` to render the `TabBar` and pass additional props.
#### Example
```js
renderTabBar={props =>
<TabBar
{...props}
indicatorStyle={{ backgroundColor: 'pink' }}
/>
}
```
#### Props
- `getLabelText`: callback which returns the label text to use for a tab. Defaults to uppercased route title.
- `getAccessible`: callback which returns a boolean to indicate whether to mark a tab as `accessible`. Defaults to `true`.
- `getAccessibilityLabel`: callback which returns an accessibility label for the tab. Defaults to route title.
- `getTestID`: callback which returns a test id for the tab.
- `renderIcon`: callback which returns a custom React Element to be used as a icon.
- `renderLabel`: callback which returns a custom React Element to be used as a label.
- `renderIndicator`: callback which returns a custom React Element to be used as a tab indicator.
- `renderBadge`: callback which returns a custom React Element to be used as a badge.
- `onTabPress`: callback invoked on tab press, useful for things like scroll to top.
- `onTabLongPress`: callback invoked on tab long-press, for example to show a drawer with more options.
- `pressColor`: color for material ripple (Android >= 5.0 only).
- `pressOpacity`: opacity for pressed tab (iOS and Android < 5.0 only).
- `scrollEnabled`: whether to enable scrollable tabs.
- `bounces`: whether the tab bar bounces when scrolling.
- `useNativeDriver`: whether to use native animations.
- `tabStyle`: style object for the individual tabs in the tab bar.
- `indicatorStyle`: style object for the active indicator.
- `labelStyle`: style object for the tab item label.
- `style`: style object for the tab bar.
### `<PagerPan />`
Cross-platform pager based on the [`PanResponder`](https://facebook.github.io/react-native/docs/panresponder.html).
#### Props
- `animationEnabled`: whether to enable page change animation.
- `swipeEnabled`: whether to enable swipe gestures.
- `swipeDistanceThreshold`: minimum swipe distance to trigger page switch.
- `swipeVelocityThreshold`: minimum swipe velocity to trigger page switch.
- `onSwipeStart`: optional callback when a swipe gesture starts.
- `onSwipeEnd`: optional callback when a swipe gesture ends.
- `onAnimationEnd`: optional callback when the transition animation ends.
- `getTestID`: optional callback which receives the current scene and returns a test id for the tab.
- `children`: React Element(s) to render.
### `<PagerScroll />`
Cross-platform pager based on [`ScrollView`](https://facebook.github.io/react-native/docs/scrollview.html) (default on iOS).
#### Props
- `animationEnabled`: whether to enable page change animation.
- `swipeEnabled`: whether to enable swipe gestures.
- `onSwipeStart`: optional callback when a swipe gesture starts.
- `onSwipeEnd`: optional callback when a swipe gesture ends.
- `onAnimationEnd`: optional callback when the transition animation ends.
- `getTestID`: optional callback which receives the current scene and returns a test id for the tab.
- `children`: React Element(s) to render.
There are some caveats when using this pager on Android, such as poor support for intial index other than `0` and weird animation curves.
### `<PagerAndroid />`
Android only pager based on `ViewPagerAndroid` (default on Android).
#### Props
- `animationEnabled`: whether to enable page change animation.
- `swipeEnabled`: whether to enable swipe gestures.
- `onSwipeStart`: optional callback when a swipe gesture starts.
- `onSwipeEnd`: optional callback when a swipe gesture ends.
- `onAnimationEnd`: optional callback when the transition animation ends.
- `keyboardDismissMode`: whether the keyboard gets dismissed in response to a drag in [ViewPagerAndroid](https://face
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
技术栈 typescript+eslint+redux+taro+react-native+mock taro适配Android、iOS、微信小程序、H5最佳实践,主要涉及到了基础网络请求的封装、适配了多端的SafeArea安全区域、style工具样式引用替换scss的繁琐写法大幅度简化代码,同时解决了scss样式无法通过className进行属性传递的问题、自定义tabBar、全局模态对话框展示(解决了微信小程序端不能覆盖底部tabBar的问题)、展示了相同组件多端适配引用的方式、多端样式布局通过styleAssign注入flex、column、relative的方式实现统一化、演示了app的消息通信,通过mock数据在本地搭建服务进行前后端分离开发、本脚手架各端适配的比较完美适合用来进行全新项目的多端开发,后续基础组件持续完善中,目标是打造一个多端共用的基础组件库. 适配进度 H5 -- 完美适配 React Native -- 完美适配 微信小程序 -- 完美适配 目标功能 打造一个多端共用的基础组件库 -- 持续开发完善中 用法: 先打开本地mock服务命令:
资源推荐
资源详情
资源评论
收起资源包目录
一个taro适配Android、iOS、微信小程序、H5最佳实践项目的脚手架 (570个子文件)
.DS_Store 8KB
.DS_Store 8KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.editorconfig 197B
loading.gif 9KB
loading.gif 9KB
.gitignore 64B
build.gradle 2KB
unimodules-core.gradle 1KB
build.gradle 1KB
UMDefines.h 3KB
UMModuleRegistry.h 1KB
UMExportedModule.h 840B
UMModuleRegistryAdapter.h 831B
UMUIManager.h 720B
UMViewManagerAdapter.h 714B
UMUtilities.h 602B
UMReactNativeAdapter.h 583B
UMBridgeModule.h 576B
UMModuleRegistryProvider.h 560B
UMNativeModulesProxy.h 545B
UMViewManagerAdapterClassesRegistry.h 521B
UMInternalModule.h 478B
UMModuleRegistryConsumer.h 440B
UMViewManager.h 430B
UMReactNativeEventEmitter.h 413B
UMAppLifecycleService.h 404B
UMLogManager.h 399B
UMEventEmitter.h 394B
UMModuleRegistryDelegate.h 337B
UMAppLifecycleListener.h 316B
UMKernelService.h 293B
UMEventEmitterService.h 256B
UMLogHandler.h 254B
UMJavaScriptContextProvider.h 236B
UMAppDelegateWrapper.h 217B
UMUtilitiesInterface.h 215B
UMSingletonModule.h 215B
UMReactLogHandler.h 204B
UMReactFontManager.h 166B
index.html 1011B
index.html 1011B
YaoRenDangGui_Taro.iml 458B
UIManagerModuleWrapper.java 10KB
NativeModulesProxy.java 8KB
ExportedModule.java 6KB
ModuleRegistry.java 5KB
ViewManager.java 4KB
MapArguments.java 4KB
MapHelper.java 3KB
ViewManagerAdapterUtils.java 3KB
ReactModuleRegistryProvider.java 3KB
EventEmitterModule.java 3KB
ModuleRegistryAdapter.java 3KB
ArgumentsHelper.java 2KB
ModuleRegistryProvider.java 2KB
ArgumentsHelper.java 2KB
ViewGroupManagerAdapter.java 2KB
SimpleViewManagerAdapter.java 2KB
ReactAdapterPackage.java 1KB
RuntimeEnvironmentModule.java 1KB
Package.java 1KB
CookieManagerModule.java 1015B
UIManager.java 987B
PromiseWrapper.java 987B
BasePackage.java 962B
ModuleRegistryReadyNotifier.java 871B
ReadableArguments.java 866B
Promise.java 833B
Arguments.java 820B
FileUtilities.java 755B
InternalModule.java 714B
FontManagerModule.java 680B
InvalidArgumentException.java 652B
CodedRuntimeException.java 626B
EventEmitter.java 595B
InvalidArgumentException.java 595B
CodedException.java 583B
DoNotStrip.java 561B
CurrentActivityNotFoundException.java 422B
ModuleNotFoundException.java 418B
KeepAwakeManager.java 354B
ActivityEventListener.java 341B
CodedThrowable.java 333B
ExpoMethod.java 288B
RuntimeEnvironmentInterface.java 263B
ExpoProp.java 210B
ModuleRegistryConsumer.java 186B
LifecycleEventListener.java 154B
ActivityProvider.java 142B
JavaScriptContextProvider.java 122B
SingletonModule.java 98B
Consumer.java 95B
Function.java 95B
共 570 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
白话机器学习
- 粉丝: 8179
- 资源: 7687
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功