Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

react-native wrapper for android BottomSheetBehavior

License

NotificationsYou must be signed in to change notification settings

cesardeazevedo/react-native-bottom-sheet-behavior

Repository files navigation

react-native wrapper for androidBottomSheetBehavior, supportsFloatingActionButton.

npm version

Demo

react-native-bottom-sheet-behavior

See the Google Maps gif implementation

v1.0.0

This major release v1.0.0 supports anchor state, which means that you can have a middle state between collapsed and expanded.

This version now uses a custom BottomSheetBehavior implementation frommiguelhincapie/CustomBottomSheetBehaviorwhich is basically a fork from the original design-support, but with anchor state support and colors management,even though is custom implementation, old version should work as before, and you can also disable theanchor state withanchorEnabled prop which is disabled by default.

Components

The following components are included in this package:

  • CoordinatorLayout
  • BottomSheetBehavior
  • FloatingActionButton
  • MergedAppBarLayout
  • ScrollingAppBarLayout
  • BackdropBottomSheet
  • BottomSheetHeader

NOTE We expose some android core components such asCoordinatorLayout,AppBarLayout,FloatingActionButton,but they are NOT meant to be general purposed, and it may not work out of the context of this library,so use at your own risk.

iOS Alternative

If you are wondering some iOS alternative, i highly recommendreact-native-interactable bywix,you can see their google maps approachhere,which is very easy to get started.

Install

$ npm install react-native-bottom-sheet-behavior

Install with RNPM

$ react-native link react-native-bottom-sheet-behavior

Install Manually

Edit the current files as follows.

android/settings.gradle

include ':app'+   include ':react-native-bottom-sheet-behavior'+   project(':react-native-bottom-sheet-behavior').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-bottom-sheet-behavior/android')

android/app/build.gradle

    dependencies {        implementation fileTree(dir: "libs", include: ["*.jar"])        implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"+       implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"        implementation "com.facebook.react:react-native:+"  // From node_modules+       implementation project(':react-native-bottom-sheet-behavior')    }

MainApplication.java

+   import com.bottomsheetbehavior.BottomSheetBehaviorPackage;    public class MainApplication extends Application implements ReactApplication {      @Override      protected List<ReactPackage> getPackages() {        return Arrays.<ReactPackage>asList(            new MainReactPackage(),+           new BottomSheetBehaviorPackage()        );      }    }

Usage

You will need to wrap your view into aCoordinatorLayout to make it work.

render(){return(<CoordinatorLayoutstyle={{flex:1}}><Viewstyle={{flex:1,backgroundColor:'transparent'}}></View><BottomSheetBehaviorref='bottomSheet'peekHeight={70}hideable={false}state={BottomSheetBehavior.STATE_COLLAPSED}><Viewstyle={{backgroundColor:'#4389f2'}}><Viewstyle={{padding:26}}><Text>BottomSheetBehavior!</Text></View><Viewstyle={{height:200,backgroundColor:'#fff'}}/></View></BottomSheetBehavior><FloatingActionButtonautoAnchorref="fab"/></CoordinatorLayout>)}

NOTEMake sure that your view has abackgroundColor style to prevent some "bugs" when rendering the container.

Components Order

You should follow this component order.

render(){return(<CoordinatorLayout><ScrollingAppBarLayout><ToolbarAndroid/></ScrollingAppBarLayout><View>Main Content</View><BackdropBottomSheet/><BottomSheetBehavior/><MergedAppBarLayout<ToolbarAndroid/></MergedAppBarLayout><FloatingActionButton/></CoordinatorLayout>)}

Events

In order to get the current bottom sheet state or offset, you can listen toonStateChange oronSlide respectively.

<BottomSheetBehavioronSlide={(e)=>console.log(e.nativeEvent.offset)}onStateChange={(e)=>console.log(e.nativeEvent.state)}/>

AppBarLayouts

We provide some custom AppBars that has custom behaviors, they automatically connects with BottomSheetBehaviorin order to connects withToolbarAndroid and toggle visibility, both AppBars can also manager StatusBar backgrounds.

Currently, AppBars only supportsToolbarAndroid as a child, you may have some troubles trying to render a custom View.

ScrollingAppBarLayout

This behavior hides and sets the StatusBar background to transparent when you starting dragging the BottomSheet,and reappears when the BottomSheet backs to the collapsed state, setting back the StatusBar background colorwithstatusBarColor prop.

scrollingappbar

MergedAppBarLayout

The MergedAppBarLayout behavior appears when the BottomSheet reaches the anchor state (or expanded state if you're not using anchorEnabled).When the BottomSheet is getting over the MergedAppBar, it will partially sets the height of ToolbarAndroid revealing themergedColor prop, and when the BottomSheet is fully expanded, it sets the ToolbarAndroid with thetoolbarColor prop.

<MergedAppBarLayouttranslucent={true}barStyle='light-content'barStyleTransparent='dark-content'mergedColor='#1abc9c'toolbarColor='#34495e'statusBarColor='#2c3e50'><ToolbarAndroidnavIconName="md-arrow-back"overflowIconName='md-more'title='React Native Bar!'titleColor='#fff'/></MergedAppBarLayout>

mergedappbar

merged_color

Translucent App Bars

Both AppBars supports translucent status bar, you can enable withtranslucent prop, which will basically adds top margins andNOT change the translucent itself, you should handle the translucent directely on the react-native StatusBar component.

FloatingActionButton

If you are using FloatingActionButton, theautoAnchor prop will automatically connect to BottomSheetBehavior,in order to follow when it's dragging.

<FloatingActionButtonautoAnchor/>

You still can do it manually though, by doing this.

componentDidMount(){this.refs.fab.setAnchorId(this.refs.bottomSheet)}

FloatingActionButton's has a custom behavior that hides when closely reaches MergedAppBarLayout.

Support for react-native-vector-icons

You can also usereact-native-vector-iconson FloatingActionButton, which will automatically load the icon for you.

importIconfrom'react-native-vector-icons/Ionicons'  ...render(){return(<FloatingActionButtonicon={"directions"}iconProvider={Icon}/>)}

You can checkGoogleMapsView.js example.

BackdropBottomSheet

This component is rendered behind the BottomSheetBehavior, and behave like a parallax when BottomSheet is dragging.you should pass a fixedheight prop that may match withanchorPoint prop from BottomSheet, in order to achieve a full screen viewwhen reaches the anchor state.

BottomSheetHeader

This component abstracts color management between BottomSheet states on the native side,it will find all and components recursively and handles everything out the box.

NestedScrollView

If you are not using the anchor point, and want to add some nested scroll, you will need to install thereact-native-nested-scroll-viewto allows you to scroll inside bottom sheet continuously.

Note thereact-native-nested-scroll-view is only useful when you areNOT using the anchorPoint.

react-native

NestedScrollView.js example

API

BottomSheetBehavior properties

PropDescriptionDefault Value
stateThe state of the bottom sheet4 (STATE_COLLAPSED)
peekHeightPeek Height value in DP50
hideableAllow hide the bottom sheetfalse
anchorEnabledEnabled anchor pointfalse
anchorPointAnchor point where the bottom sheet should stay between collapsed and expanded300
elevationElevation shadow0
onStateChangeCallback when bottom sheet state changed
onSlideCallback continuously called while the user is dragging the bottom sheet

BottomSheetBehavior States

StateDescription
1STATE_DRAGGING
2STATE_SETTLING
3STATE_EXPANDED
4STATE_COLLAPSED
5STATE_HIDDEN
6STATE_ANCHOR_POINT
BottomSheetBehavior actions
MethodDescription
setBottomSheetStateSets the bottom sheet state
FloatingActionButton properties
PropDescriptionDefault Value
srcDrawable file under the drawable android folder
autoAnchorAttachs the button on bottom sheet automaticallyfalse
iconreact-native-vector-icons name
iconProviderIcon package provided by react-native-vector-icons
iconColorIcon color
iconColorExpandedIcon expanded color when used by BottomSheetHeader
backgroundColorBackground color
backgroundColorExpandedBackground expanded color used by BottomSheetHeader
hiddenHides FloatingActionButtonfalse
rippleEffectEnable rippleEffecttrue
rippleColorRipple color
elevationElevation shadow18
onPressCallback called when touch is released
FloatingActionButton actions
MethodDescription
showThis method will animate the button show if the view has already been laid out
hideThis method will animate the button hide if the view has already been laid out
setAnchorIdAttachs the button on bottom sheet by passing it as a argument (no needed if autoAnchor is set true)
ScrollingAppBarLayout properties
PropDescription
heightHeight of ScrollingAppBarLayout
statusBarColorActive status bar color
translucentAdds top margins on the AppBar to not draw behind the status bar
barStyleStatus Bar style, (default, light-content, dark-content), used when the ScrollingAppBarLayout is present
barStyleTransparentStatus Bar style, (default, light-content, dark-content), used when the ScrollingAppBarLayout is not present and the StatusBar is transparent
MergedAppBarLayout properties
PropDescription
heightHeight of ScrollingAppBarLayout
mergedColorMerged color when the bottom sheet is overlaying with ToolbarAndroid
toolbarColorThe final ToolbarAndroid color when the bottom sheet is fully expanded
statusBarColorActive status bar color when bottom sheet is expanded
translucentAdds top margins on the AppBar to not draw behind the status bar
barStyleStatus Bar style, (default, light-content, dark-content), used when the BottomSheet is fully expanded
barStyleTransparentStatus Bar style, (default, light-content, dark-content), used when the AppBar is transparent
BottomSheetHeader properties
PropDescription
textColorExpandedThe state of the bottom sheet
backgroundColorBackground color when collased
backgroundColorExpandedBackground color when anchored or expanded
onPressCallback called when header touch is released

License

MIT

About

react-native wrapper for android BottomSheetBehavior

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp