GithubHelp home page GithubHelp logo

rn-bottom-drawer's Introduction

Bottom drawer for React Native

Demo gif

Content

Installation

Install rn-bottom-drawer.

npm install rn-bottom-drawer --save

Usage Example

(go to the example folder for a more fleshed out example)

import React from 'react';
import { View, Text } from 'react-native';
import BottomDrawer from 'rn-bottom-drawer';

const TAB_BAR_HEIGHT = 49;

export default class App extends React.Component {
  renderContent = () => {
    return (
      <View>
        <Text>Get directions to your location</Text>
      </View>
    )
  }

  render() {
    return (
      <BottomDrawer
        containerHeight={100}
        offset={TAB_BAR_HEIGHT}
      >
        {this.renderContent()}
      </BottomDrawer>
    )
  }
}

Refer to this code if you want to put a scrollview within the bottom drawer

Configuration

Prop Type Default Description
containerHeight number -- The height of the drawer.
offset number 0 If your app uses tab navigation or a header, offset equals their combined heights. In the demo gif, the offset is the header + tab heights so that the drawer renders correctly within the map view.
downDisplay number containerHeight / 1.5 When the drawer is swiped into down position, downDisplay controls how far it settles below its up position. For example, if its value is 20, the drawer will settle 20 points below the up position. The default value shows 1/3 of the container (if containerHeight = 60, the default downDisplay value = 40).
backgroundColor string '#ffffff' The background color of the drawer.
startUp bool true If true, the drawer will start in up position. If false, it will start in down position.
roundedEdges bool true If true, the top of the drawer will have rounded edges.
shadow bool true if true, the top of the drawer will have a shadow.
onExpanded func -- A callback function triggered when the drawer is swiped into up position
onCollapsed func -- A callback function triggered when the drawer is swiped into down position

Questions?

Feel free to contact me at [email protected] or create an issue

rn-bottom-drawer's People

Contributors

abduraufsherkulov avatar edxds avatar jacklein 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

rn-bottom-drawer's Issues

Error

How to run react-native-cli

getLayout <<NaN>>

The getLayout method returns an error when the left side returns NaN. This should be a default value.

And also do not need the left value.

Error:

Invariant Violation: Invariant Violation: [143,"RCTView",{"left":"<<NaN>>","top":563.4285714285714}] is not usable as a native method argument

screen shot 2019-03-06 at 20 11 49

Dyanamic Height for different screens

@jacklein
I am using rn-bottom-drawer for drawer implementation for my app. I tried several ways like PixelRatio, ModerateScale, If-else for range of screen height but i am unsuccessful in setting such a containerHeight that it works perfectly with all device screens and there is no space between my drawer and bottom of my screen.

My Code:

<BottomDrawer
        ref={"_drawer"}
        containerHeight={moderateScale(270)}
        startUp={false}
        backgroundColor={null}
        downDisplay={moderateScale(200)}
        onExpanded={() => this.setState({ isRecentSearchesExpanded: true })}
        onCollapsed={() => this.setState({ isRecentSearchesExpanded: false })}>
        <View style={{ width: screenWidth }}>
                <ImageBackground 
                         source={require('../../assets/tabBkgd.png')} 
                         style={{ 
                                height: "100%", 
                                width: screenWidth, 
                                 justifyContent: "center", 
                                 backgroundColor: "transparent" }} 
                         resizeMode="stretch">
                    {/* some views here */}
                </ImageBackground>
         </View>
</BottomDrawer>

Error: AnimatedValue: Attempting to set value to undefined

Using react-native: 0.66.5, I get this error: Error: AnimatedValue: Attempting to set value to undefined.

The problem is in Animator.js, in _handlePanResponderMove method in which only "y" property is updating, missing "x" property.

I provided a PR with this fix.

error module:metro-react-native-babel-preset

error: bundling failed: Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/var/www/rnp/node_modules/rn-bottom-drawer"
at /var/www/rnp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map ()

Layout error

I get Malformed calls from JS:field sizes are different. Tried everything from issues still the same no matter what I do.

Update downDisplay prop dyamamicaly

Hello,

Good work on this! Is there a way to update the displayDown value after dynamically setting a state value? Heres what Im working with!

const HEADER_HEIGHT = 50;
const CONTAINER_HEIGHT = 300;
var DOWN_DISPLAY = 0 ;

export default class Drawer extends React.Component {

    state = {
        height:0,
    }
    
    handleLayout = ({nativeEvent}) => {
        this.setState({height: CONTAINER_HEIGHT - nativeEvent.layout.height});
    }
    renderContent = () => {
        return (
        <View style={styles.drawerContainer}>
            <TouchableOpacity 
                onPress={this._onPressButton}
                style={styles.grip}            
            />
            <View style={styles.HeaderBar} onLayout={this.handleLayout}>
                <Text style={[styles.H1,styles.header]}>Discover</Text>
                <StoryBarCat title="Test" icon={require("commonwealth/assets/svgs/color-circle.svg")}/>
            </View>
            <View style={styles.tabContent}>
            <Text>HERES SOME MORE TEXT</Text>
            </View>
        </View>
        )
    }

    render() {
        return (
        <BottomDrawer
            containerHeight={300}
            offset={0}
            roundedEdges={true}
            downDisplay={this.state.height}
            startUp={false}
            backgroundColor="#455154"
        >
            {this.renderContent()}
        </BottomDrawer>
        
        )
    }
}

iPhone X

How do I calculate the offset (or give a option) to drawer on iPhone X and above versions?
It is rendering the drawer view ignoring the safe area, so the drawer is positioned lower than usual. Is there any options for iPhone X and above versions to position the drawer properly?

Cannot interact with elements behind drawer (i.e. map)

My current code (react-native-maps & rn-bottom-drawer nested in the components shown):

{/* Maps Component */}
<JobLocator/>

{/* Jobs Bottom Drawer Component */}
<JobsBottomDrawer navigation={navigation}/>

This layers the elements appropriately with the map behind the drawer and the drawer functions as expected, but when I try to interact with the map it is not responsive. I comment out the drawer component and I can interact with the map just fine. Please let me know if this is a known issue or if I have done something incorrectly and I will proceed accordingly. Thanks!

toggle the drawer state

hello! is there any way to change the drawer's mode (opened to closed/closed to opened) by a button or touchable opacity?

cross platform testing

My laptop is too old to download xcode so I cannot test on an iphone x simulator to see what it looks like. I'm also working on setting up the android simulator but if anyone could test on these devices and see if there's any problems that would be great!

Typescript compatible?

Hi, I want to use this library. However, the language that I use is typescript and seems like I can't use the library. Is it typescript compatible?
image

Three positions

I see that the drawer has two positions: Up & Down.
I'm trying to put a middle inbetween

 this.UP_POSITION = this._calculateUpPosition(SCREEN_HEIGHT, this.props.containerHeight, this.props.offset)
    this.DOWN_POSITION = this._calculateDownPosition(this.UP_POSITION, this.DOWN_DISPLAY)

    this.state = { currentPosition: this.props.startUp ? this.UP_POSITION : this.DOWN_POSITION, currentState: this.props.startUp ? UP_STATE : DOWN_STATE };

scroll callbacks

Can we get scroll callbacks with amount of scroll so that we can perform any animation or any other processing?

When I am sliding down the drawer when its in collapsed state, the onExpanded function is still calling

So I wanted to change the content of the drawer when it gets expanded. So I have 2 components, one will render when the drawer is in the collapsed state and one when the drawer is expanded. But when i am even touching the drawer, the onExpanded gets called and the expanded component gets render even if the drawer is not opened.

The component renders even if the drawer is pulled downwards when it is in a collapsed state

Deformity, when turning the screen sideways

when i turned the screen sideways the drawer disappear + if I run app while phone horizontal, and change the possition to vertical the drawer staying up and i could't hide it anymore.

Screenshot_2020-03-09-09-53-57-945_com map_project

AnimatedValue: Attempting to set value to undefined

Hi, I'm trying to use rn-bottom-drawer, but get error message as the title when I swipe up, the error produces on both platform android and iOS.

<BottomDrawer containerHeight={Dimensions.get('window').height / 2} offset={0} startUp={false} roundedEdges={true} shadow={true}>
                    <View style={{ flex: 1 }}>
                            <Text>Hi</Text>
                   </View>
</BottomDrawer>

my react native version is: 0.63.2 and latest rn-bottom-drawer.

useNativeDriver required

Error: "Animated: useNativeDriver was not specified. This is a required option and must be explicitly set to true or false"

Full screen height

I want container size take full screen and user can toggle it.

How to achieve?

Error when using with Typescript

Here's the error that I get:

.../node_modules/rn-bottom-drawer/src/BottomDrawer.js 13:19
Module parse failed: Unexpected token (13:19)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| export default class BottomDrawer extends Component{
>   static propTypes = {
|     /**
|      * Height of the drawer.

(When creating with expo, I used blank (TypeScript). What do I do?

Default position bottom

When I have implemented this plugin The view initialized as a full screen but I want that the view should be minimized by deafult If I drag then it should full screen. How can I achieve this?

ScollView does not work within the drawer

My code displays the view with the items going off the screen but the view will not scroll. I have tried messing with zIndex and wrapping in views etc with no luck. I have also tried a vertical scroll view and it does not scroll either. Any help is appreciated.

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.