Coder Social home page Coder Social logo

rnparallax's Introduction

RNParallax (react-native-parallax-header)

GitHub stars GitHub forks GitHub issues

NPM

Installation

$ npm i react-native-parallax-header --save

Demo

iPhone X or XS (Using alwaysShowTitle={false} & alwaysShowNavBar={false})

iPhone X

iPhone X or XS

iPhone X

iPhone 8

iPhone 8

Example

Refer to TestParallax for working example

import React from 'react';
import {
  StyleSheet,
  View,
  Text,
  StatusBar,
  Dimensions,
  TouchableOpacity,
} from 'react-native';
import ReactNativeParallaxHeader from 'react-native-parallax-header';

const {height: SCREEN_HEIGHT} = Dimensions.get('window');

const IS_IPHONE_X = SCREEN_HEIGHT === 812 || SCREEN_HEIGHT === 896;
const STATUS_BAR_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 44 : 20) : 0;
const HEADER_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 88 : 64) : 64;
const NAV_BAR_HEIGHT = HEADER_HEIGHT - STATUS_BAR_HEIGHT;

const renderNavBar = () => (
  <View style={styles.navContainer}>
    <View style={styles.statusBar} />
    <View style={styles.navBar}>
      <TouchableOpacity style={styles.iconLeft} onPress={() => {}}>
        <Text style={{color: 'white'}}>About</Text>
      </TouchableOpacity>
      <TouchableOpacity style={styles.iconRight} onPress={() => {}}>
        <Text style={{color: 'white'}}>Me</Text>
      </TouchableOpacity>
    </View>
  </View>
);

const renderContent = () => {
  return (
    <View style={styles.body}>
      {Array.from(Array(30).keys()).map((i) => (
        <View
          key={i}
          style={{padding: 15, alignItems: 'center', justifyContent: 'center'}}>
          <Text>Item {i + 1}</Text>
        </View>
      ))}
    </View>
  );
};

const title = () => {
  return (
    <View style={styles.body}>
      <Text style={{color: 'white', fontSize: 25}}>Parallax Header</Text>
    </View>
  );
};

const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <ReactNativeParallaxHeader
        headerMinHeight={HEADER_HEIGHT}
        headerMaxHeight={250}
        extraScrollHeight={20}
        navbarColor="#3498db"
        titleStyle={styles.titleStyle}
        title={title()}
        backgroundImage={require('./bg.png')}
        backgroundImageScale={1.2}
        renderNavBar={renderNavBar}
        renderContent={renderContent}
        containerStyle={styles.container}
        contentContainerStyle={styles.contentContainer}
        innerContainerStyle={styles.container}
        scrollViewProps={{
          onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
          onScrollEndDrag: () => console.log('onScrollEndDrag'),
        }}
      />
    </>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  contentContainer: {
    flexGrow: 1,
  },
  navContainer: {
    height: HEADER_HEIGHT,
    marginHorizontal: 10,
  },
  statusBar: {
    height: STATUS_BAR_HEIGHT,
    backgroundColor: 'transparent',
  },
  navBar: {
    height: NAV_BAR_HEIGHT,
    justifyContent: 'space-between',
    alignItems: 'center',
    flexDirection: 'row',
    backgroundColor: 'transparent',
  },
  titleStyle: {
    color: 'white',
    fontWeight: 'bold',
    fontSize: 18,
  },
});

export default App;

API Usage

Property Type Required Description Default
renderNavBar func No This renders the nav bar component Empty <View />
renderContent func YES This renders the scroll view content -
headerMaxHeight number No This is the header maximum height Default to 170
headerMinHeight number No This is the header minimum height Default to common ios & android navbar height (have support for iPhone X too :p)
backgroundImage image source No This renders the background image of the header (if specified, background color will not take effect) Default to null
backgroundImageScale number No This is the image scale - either enlarge or shrink (after scrolling to bottom & exceed the headerMaxHeight) Default is 1.5
backgroundColor string No This is the color of the parallax background (before scrolling up), will not be used if backgroundImage is specified Default color is #303F9F
extraScrollHeight number No This is the extra scroll height (after scrolling to bottom & exceed the headerMaxHeight) Default is 30
navbarColor string No This is the background color of the navbar (after scroll up) Default color is #3498db
statusBarColor string No This is the status bar color (for android) navBarColor will be used if no statusBarColor is passed in Default to null
title any No This is the title to be display in the header, can be string or component Default to null
titleStyle style No This is the title style to override default font size/color Default to color: ‘white’ text and fontSize: 16
headerTitleStyle style No This is the header title animated view style to override default <Animated.View> style Default to null
scrollEventThrottle number No This is the scroll event throttle Default is 16
contentContainerStyle style No This is the contentContainerStyle style to override default <ScrollView> contentContainerStyle style Default to null
containerStyle style No This is the style to override default outermost <View> style Default to null
scrollViewStyle style No This is the scrollview style to override default <ScrollView> style Default to null
innerContainerStyle style No This is the inner content style to override default <View> style inside <ScrollView> component Default to null
alwaysShowTitle bool No This is to determine whether show or hide the title after scroll Default to true
alwaysShowNavBar bool No This is to determine whether show or hide the navBar before scroll Default to true
scrollViewProps object No This is to override default scroll view properties Default to {}

rnparallax's People

Contributors

dmitrika avatar kyaroru avatar stoneman1 avatar waghih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rnparallax's Issues

Example is not running.

There is a problem in Example. Can you share full codes of example? Also, i want to add Tab below Image. How should i edit this example?

My Tab Codes:

<ScrollableTabView
    style={styles.container}
    renderTabBar={()=><DefaultTabBar backgroundColor='rgba(255, 255, 255, 0.7)' />}
    tabBarPosition='overlayTop'
  >
    <ScrollView tabLabel='iOS'>
      <Icon name='logo-apple' color='black' size={300} style={styles.icon} />
      <Icon name='ios-phone-portrait' color='black' size={300} style={styles.icon} />
      <Icon name='logo-apple' color='#DBDDDE' size={300} style={styles.icon} />
      <Icon name='ios-phone-portrait' color='#DBDDDE' size={300} style={styles.icon} />
    </ScrollView>
    <ScrollView tabLabel='Android'>
      <Icon name='logo-android' color='#A4C639' size={300} style={styles.icon} />
      <Icon name='logo-android' color='black' size={300} style={styles.icon} />
      <Icon name='logo-android' color='brown' size={300} style={styles.icon} />
    </ScrollView>
  </ScrollableTabView>

BackgroundImage is not displaying in android & How to remove title in backgroundImage and how to display the title only if header is visible?

Hi, i am using this RNParallax module it's working fine. But i want to customize the backgroundImage. My questions is:-

  1. BackgroundImage is not displaying while passing uri in android devices.
  2. How to remove title in backgroundImage and how to display the title only if header is visible?

Code:-

  <ReactNativeParallaxHeader
            headerMinHeight={64}
            headerMaxHeight={250}
            extraScrollHeight={20}
            navbarColor="#3498db"
            alwaysShowTitle={false}
            // alwaysShowNavBar={this.state.showNavBar}
            // title="Parallax Header"
            titleStyle={styles.titleStyle}
            backgroundImage={{
              uri:
                'https://images.unsplash.com/photo-1500322969630-a26ab6eb64cc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMjU4fQ&w=1000&q=80',
            }}
            backgroundImageScale={1.2}
            renderNavBar={this.renderNavBar.bind(this)}
            renderContent={this.renderContent.bind(this)}
            containerStyle={styles.container}
            contentContainerStyle={styles.contentContainer}
            innerContainerStyle={styles.container}
            navbarColor="black"
            scrollViewProps={{
              onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
              onScrollEndDrag: () => console.log('onScrollEndDrag'),
            }}
          />

Versions:-
react-native: "0.61.4"
react-native-parallax-header: "^1.1.3"

Screenshots:-
iOS:-
Screenshot 2019-11-11 at 12 14 09 PM
Android:-
Screenshot 2019-11-11 at 12 15 02 PM

Unable to override hardcoded background color

I have an app where I use fullscreen background image and I have ReactNativeParallaxHeader inside of the ImageBackground like:

<ImageBackground source={images.background} style={{ flex: 1, width: null, height: null }}...>
  <ReactNativeParallaxHeader .../>
</ImageBackground>

Currently this library creates fullscreen <View style={styles.container}> container with hardcoded background color:

container: {
    backgroundColor: 'white',
    flex: 1,
  },

This container hides my background image completely. I did not find any ways to bypass this, except modifying the library source code by setting container backgroundColor to "transparent".

So maybe change the default value to transparent or make it configurable through props?

Module break, not scrolling

@kyaroru :
Hi, I tried the form here is the example link: https://snack.expo.io/r1Ck3agvM
As you can see, it does not allow the elements in the tab to be scrolled.
I would also like the tab to crash when the toolbar reaches the minimum height.
That is, it should scroll only the elements of the tab, without scrolling the tab.
How can I do?

Example for iPhone X or XS

Is the example source code for iPhone X or XS (Using alwaysShowTitle={false} & alwaysShowNavBar={false}) available?

Thanks

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

PropTypes missmatch at titleStyle props

According to README, titleStyle's proptypes is style. Unfortunately, when I try to change fontFamily and fontSize style attribute value into titleStyle props, I got Warning: Failed prop type of type 'object', expected number warning message.

Crashing on setting a value to renderNavBar using states

Hi, the library works fine except for this issue.

render() {
        return (
            <View style={styles.mainContainer}>
                <ReactNativeParallaxHeader
                    headerMinHeight={100}
                    headerMaxHeight={250}
                    extraScrollHeight={0}
                    navbarColor={AppConfigurations.branding.appThemeColour}
                    backgroundImage={require('./../../images/kiosk-starter-page/background.jpg')}
                    backgroundImageScale={1}
                    renderNavBar={this.renderNavBar}
                    renderContent={this.renderContent}
                />
            </View>
        );
    }

renderNavBar() {
        return(
            <View style={{flex: 1, flexDirection: 'column', justifyContent: 'flex-end', padding: 20}}>
                <Text>{this.state.userName}</Text>
            </View>
        )
    }

State is simply an empty string and the following error gets printed.

simulator screen shot - ipad pro 9 7-inch - 2018-05-22 at 14 45 52

Also, is there a way to add an blur overlay or gradient over the parallax image? Thank you.

refreshControl

Hello,

I want to use refreshControl with my FlatList, but it doesn't work.
When I remove ReactNativeParallaxHeader, the refreshControl works
Can you help me ?

Thanks

import React from 'react';
import {
  View,
  Text,
  Image,
  TouchableOpacity,
  Alert,
  FlatList,
  Dimensions,
  Platform,
  StyleSheet,
  RefreshControl
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import ReactNativeParallaxHeader from 'react-native-parallax-header';

import styles from './style';
import shop from '../../services/api/shop';
import HeaderComponent from '../../components/Header';
import IconComponent from '../../components/Icon';

const {width, height} = Dimensions.get('window');
const IS_IPHONE_X = height === 812 || height === 896;
const STATUS_BAR_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 44 : 20) : 0;
const HEADER_HEIGHT = Platform.OS === 'ios' ? (IS_IPHONE_X ? 98 : 100) : 74;
const NAV_BAR_HEIGHT = HEADER_HEIGHT - STATUS_BAR_HEIGHT;

const stylesHeader = StyleSheet.create({
  container: {
    flex: 1,
  },
  contentContainer: {
    flexGrow: 1,
  },
  navContainer: {
    height: HEADER_HEIGHT,
    marginHorizontal: 10,
  },
  statusBar: {
    height: STATUS_BAR_HEIGHT,
    backgroundColor: 'transparent',
  },
  navBar: {
    height: NAV_BAR_HEIGHT,
    justifyContent: 'space-between',
    alignItems: 'center',
    flexDirection: 'row',
    backgroundColor: 'transparent',
  },
  titleStyle: {
    color: 'white',
    fontSize: 25,
  },
  iconLeft: {
    alignItems: 'center',
    justifyContent: 'center'
  }
});


export default class ShopScreen extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      shops: [],
      isFetching: false,
      isLoaded: false
    };
  }

  // API : set shops to state
  componentWillMount() {
    shop.getShops()
      .then(shops => {
        console.log('2', shops);

        this.setState({shops: shops})
      })
      .catch((error) => {
        console.log(error);
        Alert.alert('Erreur', 'Impossible de récupérer les shops')
      })
      .finally(() => this.setState({isLoaded: true}));
  }

  test() {
    shop.getShops()
      .then(shops => this.setState({shops: shops}))
      .catch((error) => Alert.alert('Erreur', 'Impossible de récupérer les shops'))
      .finally(() => this.setState({isLoaded: true, isFetching: false}));
  }

  _onRefresh() {
    console.log('refresh');
    this.setState({ isFetching: true }, function() { this.test() });
   }

  _showDetail(shop) {
    this.props.navigation.navigate('Product', {shop: shop});
  }

  _goBasket() {
    this.props.navigation.navigate('Order');
  }

  _renderItem(shop) {
    return (
      <View style={styles.card}>
        <TouchableOpacity onPress={() => this._showDetail(shop)}>
          <Image style={styles.image} source={shop.image} />
          <View style={styles.container}>
            <Text style={styles.title}>{shop.name}</Text>
            <Text style={styles.time}>{`10-15 min`}</Text>
          </View>
        </TouchableOpacity>
      </View>
    );
  }

  renderNavBar = () => (
    <View style={stylesHeader.navContainer}>
      <View style={stylesHeader.statusBar} />
      <View style={stylesHeader.navBar}>
        <TouchableOpacity style={stylesHeader.iconLeft} onPress={() => {}}>
          <IconComponent
            style={{color: 'white', marginRight: 0}}
            iosName={`ios-options`}
            androidName={`md-options`}
            size={30} />
        </TouchableOpacity>
        <TouchableOpacity style={stylesHeader.iconRight} onPress={() => this._goBasket()}>
          <IconComponent
            style={{color: 'white', marginRight: 0}}
            iosName={`ios-basket`}
            androidName={`md-basket`}
            size={30} />
        </TouchableOpacity>
      </View>
    </View>
  )

  render() {
    const { shops, isLoaded } = this.state;
    return (
      <View style={styles.container}>
        <ReactNativeParallaxHeader
          headerMinHeight={HEADER_HEIGHT}
          headerMaxHeight={120}
          extraScrollHeight={20}
          navbarColor="#34C47C"
          backgroundColor="#34C47C"
          title="Shop"
          titleStyle={stylesHeader.titleStyle}
          renderNavBar={this.renderNavBar}
          renderContent={() => {
            return(
              <View style={styles.container}>
                <View style={styles.container}>
                  <FlatList
                    data={shops}
                    refreshControl={
                       <RefreshControl
                        refreshing={this.state.isFetching}
                        onRefresh={this._onRefresh}
                       />
                     }
                    keyExtractor = {(item, index) => index.toString()}
                    renderItem={({item}) => this._renderItem(item)} />
                </View>
              </View>
            );
          }}
          containerStyle={stylesHeader.container}
          contentContainerStyle={stylesHeader.contentContainer}
          innerContainerStyle={stylesHeader.container}
          scrollViewProps={{
            onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
            onScrollEndDrag: () => console.log('onScrollEndDrag')
          }}
        />
      </View>
    );
  }
}

Make background header clickable

I'm trying to make this background header clickable breaking my head off and I couldn't achieve it, at least in Android, haven't tested in iOS yet, but i need to make it work on both either way.

Attempted using a TouchableOpacity within Animated.View, outside of the Animated.Image, even making an AnimatedTouchable but still, wasn't able to make it work.

Any ideas?

Cant scroll when use nested tabview on android

Hello,

I am using this library via renderContent prop, its perfectly working on iOS, but not on android despite scrollenabled=false

This is my using order:

<RNParallaxHeader
....
renderContent={renderContent}
/>




 const renderContent = () => {
    return (
...

<<ScrollableTabView>
  <View>
    <Flatlist
          ...
         scrollEnabled=false
         renderItem={this.renderItems}
     />
  </View>
</ScrollableTabView>

)
}




renderItems=()=> { 

return (
<ListItem ... />
)

}

Its working exactly how i want at iOS, but on android its not working.

Any suggestion ?

How to handle edge case when scrollable content offset is less than header height

Hi, Thank you for an awesome plugin.

I have an interesting challenge where I am curios to know how to handle the following case.

I have a view where content exceeds the view with an expanded header by a small amount. When you scroll to the bottom of the screen, the header is in transition between the expanded header and the collapsed header. The content cannot scroll more unless you add more space below to compensate for the height of the header.

The other caveat here is that in the view I have a button that needs to stick to the bottom of the screen on larger devices but when displayed on smaller devices it should scroll as normal to the end, taking into consideration of the height of the header collapsing.

Is it possible to apply an overlay to the background image?

Hello,
It seems I'm not able to apply an overlay to the background image.
As I'm using an image with a lot of white and I do not want to change the text color to be black, I was looking for a way to darken the image.

How can I achieve that?

Thank you beforehand.

Issue: Can not use state data FlatList in renderContent?

Hello,
thank you so much for nice plugin, but it can not apple data list to renderContent. it is said undefined example

constructor(props) { super(props); this.state = { users: [ { id: 1, fullName: 'Ritesh Deshmukh', url: require('@assets/8.jpg'), }, ] }; }

it is said undefined users

renderContent() {
return (
<FlatList
data={this.state.users}
keyExtractor={(item, index) => item + index || item.id || index.toString()}
listKey={(index) => index.toString()}
refFlatlist={(ref) => { this.refFlatlist = ref; }}
onEndReachedThreshold={2.5}
scrollEnabled={false}
showsHorizontalScrollIndicator={false}
renderItem={({ item }) => (

)}
/>

    );
}

Hide navbar title in parallax header

Hi

I have this issue wherein the title props is immediately displayed in the parallax header. Is there a way that the title will only be displayed once I scroll?

Screen Shot 2019-04-14 at 11 29 45 AM

TypeError: renderContent is not a function

Hi,

I tried to run this on my test app and kept getting the 'TypeError: renderContent is not a function'.

I haven't made any changes to your code, could you please assist with this?

simulator screen shot - iphone x - 2018-05-20 at 16 15 20

回到顶部的操作

作者 我想问一下 如果数据比较多的情况下 有没有一个回到顶部的方法或者事件啊 我这边尝试了几种还是不行

StatusBar android

Hi, I have this problem with status Bar on android. I cant set transparent when i have image.

How can i fix this problem?

image

and my code:
image

ScrollView area not completely responsive to scroll swipe on top

There are like 60px beneath the parallax header where the content is, that no matter what or how I swipe, it won't detect my swipe, but 60ish below that it will.

My current setup is this one, height is the screen's height.

headerMinHeight={height * 0.3} 
headerMaxHeight={height / 2}

Rest is pretty default as the example.

What could be the reason of this weird behavior?

Example is cool :p

Could you fix your example and import the right stuff or add an example file... Sorry for the title but I don't know if this was done on purpose or you guys are so lazy/careless to do that

scrollToOffset doesnt works

I need to automate scroll to certain y position. Then i use scrollToOffset function from FlatList. but it doesnt work in here.

So is there any other way to do that?

rendercontent not showing when i use fetch state data

`{this.state.datas.map((data, i) => {
return (

                <ReactNativeParallaxHeader key={data.id}
                  headerMinHeight={HEADER_HEIGHT}
                  headerMaxHeight={100}
                  extraScrollHeight={40}
                  navbarColor="#6518F4"
                  title={data.title}
                  titleStyle={styles.titleStyle}
                  backgroundImage={{uri: data.image}}
                  backgroundImageScale={1.2}
                  renderNavBar={this.renderNavBar}
                  renderContent={() => {
                    return(
                      <View style={styles.container}>
                        <View style={styles.container}>
                        <Text>adasd</Text>
                        <Text>adasd</Text>
                        <Text>adasd</Text>
                        <Text>adasd</Text>
                        <Text>adasd</Text>

                        </View>
                      </View>
                    );
                  }}
                  containerStyle={styles.container}
                  contentContainerStyle={styles.contentContainer}
                  innerContainerStyle={styles.container}
                  scrollViewProps={{
                    onScrollBeginDrag: () => console.log('onScrollBeginDrag'),
                    onScrollEndDrag: () => console.log('onScrollEndDrag'),
                  }}
                />
                 
                     );
                 })}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.