0.2.19 • Published 3 years ago

rn-custom-sticky-parallax-header v0.2.19

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Introduction

Tabbed HeaderAvatar HeaderDetails Header
Tabbed Header GifAvatar Header GifDetails Header Gif

In Use

Check the live demo on Expo Snack here.

Predefined headers can be accessed through headerType="HeaderName" property, each header can be configured according to your demands using the wide amount of properties. You can change all of them, or use it right out of the box with as little changes as possible to use it for your needs

This is how you can add them in your app:

import React from 'react'
import StickyParallaxHeader from 'react-native-sticky-parallax-header'

const TestScreen = () => (
  <>
    <StickyParallaxHeader headerType="TabbedHeader" />
    {/* <StickyParallaxHeader headerType="AvatarHeader" /> */}
    {/* <StickyParallaxHeader headerType="DetailsHeader" /> */}
  </>
)

export default TestScreen

Below are examples of those components and description of the props they are accepting.

Shared props

Tabbed Header, Details Header, Avatar Header

PropertyTypeOptionalDefaultDescription
backgroundColorstringYes#1ca75dHeader background color
backgroundImagenumberYesnullSets header background image
bouncesboolYestrueBounces on swiping up
contentContainerStylesView.propTypes.styleYesSet style for content container
headerHeightnumberYesifIphoneX(92, constants.responsiveHeight(13))
renderBodyfuncYestitle => <RenderContent title={title} />Function that renders body of the header (can be empty)
snapToEdgeboolYestrueBoolean to fire the function for snap To Edge
scrollReffunc or objectYesnullScrollView body ref. Allows programmatically scroll body ScrollView
keyboardShouldPersistTaps'always', 'never', 'handled', false, trueYesundefinedDetermines when the keyboard should stay visible after a tap.
refreshControlRefreshControlYesundefinedProps used to add pull to refresh functionality.

Details Header, Avatar Header

PropertyTypeOptionalDefaultDescription
hasBorderRadiusbooleanNotrueAdds radius to header's right bottom border
imageImageSourcePropTypeNorequire('../../assets/images/photosPortraitBrandon.png')Sets header image
leftTopIconImageSourcePropTypeNorequire('../../assets/icons/iconCloseWhite.png')Set icon for left top button
leftTopIconOnPress() => voidNo() => {}Define action on left top button press
rightTopIconImageSourcePropTypeNorequire('../../assets/icons/Icon-Menu.png')Set icon for right top button
rightTopIconOnPress() => voidNo() => {}Define action on right top button press

Tabbed Header

Tabbed Header Gif

PropertyTypeOptionalDefaultDescription
foregroundImageoneOfType([object, number])YesSet image in the foreground
headerfuncYesFunction that renders custom header
logofuncYesrequire('../../assets/images/logo.png')Set header logo
logoStylestyleYes{ height: 24, width: 142 }Set header logo style
logoContainerStylestyleYes{ width: '100%', paddingHorizontal: 24, paddingTop: Platform.select({ ios: ifIphoneX(50, 40), android: 55 }), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center'}Set header logo container style
logoResizeMode"contain", "cover", "stretch", "center", "repeat"Yes"contain"Set header logo resize mode
onReffuncYesReference callback. You can call goToPage(pageNumber) method through ref to programmatically navigate to given tab
rememberTabScrollPositionboolYesfalseWhen switching between tabs remember current scroll position
scrollEventfuncYesScroll event to apply custom animations
tabs{ content: ReactElement;title?: string;icon?: ReactElement | (isActive: boolean) => ReactElement);Yes[{title: 'Popular',content: <RenderContent title="Popular Quizes" />},...]Array with tabs names, icons and content
tabTextStyleText.propTypes.styleYes{fontSize: 16, lineHeight: 20, paddingHorizontal: 12, paddingVertical: 8, color: colors.white}Set inactive tab style
tabTextActiveStyleText.propTypes.styleYes{fontSize: 16, lineHeight: 20, paddingHorizontal: 12, paddingVertical: 8, color: colors.white}Set active tab stylee
tabTextContainerStyleViewPropTypes.styleYes{backgroundColor: colors.transparent, borderRadius: 18}Set inactive tab container style
tabTextContainerActiveStyleViewPropTypes.styleYes{backgroundColor: colors.darkMint}Set active tab container style
tabWrapperStyleViewPropTypes.styleYes{paddingVertical: 12}Set single tab container style
tabsContainerStyleViewPropTypes.styleYesSet whole tab bar container style
titlestringYes"Mornin' Mark! \nReady for a quiz?"Sets header title
titleStyleText.propTypes.styleYesSet style for text in foreground

Check how to customise Tabbed Header example

Details Header

Details Header Gif

PropertyTypeRequiredDefaultDescription
iconNumbernumberNo10Set amount of cards shown on icon
tagstringNo"Product Designer"Sets header tag name
titlestringNo"Design System"Sets header title

Avatar Header

Avatar Header Gif

PropertyTypeOptionalDefaultDescription
foreground() => ReactElementNo-Function that renders the foreground of the header
header() => ReactElementNo-Function that renders custom header
parallaxHeightnumberNo-Set parallax header height
scrollEvent(event: NativeSyntheticEvent<NativeScrollEvent>) => voidNorequire('../../assets/icons/Icon-Menu.png')Scroll event to apply custom animations
snapStartThresholdnumberNo-Set start value Threshold of snap
snapStopThresholdnumberNo-Set stop value Threshold of snap
snapValuenumberNo-Set value where header is closed
subtitlestringNo"Coffee buff. Web enthusiast. Unapologetic student. Gamer. Avid organizer."Sets description(subtitle) section
titlestringNo"BrandonSets header title
transparentHeaderbooleanNofalseSet header transparency to render custom header

Custom Header

Custom header props and example

Handling StickyParallaxHeader body ScrollView reference

As callback function

<StickyParallaxHeader
  scrollRef={(ref) => {
    paralaxScrollRef.current = ref;
  }}
  foreground={this.renderForeground()}
  header={this.renderHeader()}
>
  {renderBody()}
</StickyParallaxHeader>

As useRef value

const paralaxScrollRef = useRef(null);

<StickyParallaxHeader
  scrollRef={paralaxScrollRef}
  foreground={this.renderForeground()}
  header={this.renderHeader()}
>
  {renderBody()}
</StickyParallaxHeader>

Handling nested scrollables

Handling nested flatlist props and example

Changing Statusbar style

Changing StatusBar style

Pull to refresh

Pull to refresh

Rendering icons in tabs

Icons in tabs

Prerequisites

Installation

For React Native >= 0.60.0 use version 0.0.60 and above, for previous React Native versions use 0.0.59

Installation for React Native >= 0.60.0

Add latest package version

$ yarn add react-native-sticky-parallax-header

Installation for React Native < 0.60.0

Installation steps for React Native < 0.60.0

Contributing guidelines

License

The gem is available as open source under the terms of the MIT License.

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago