Code Monkey home page Code Monkey logo

react-native-scaling-drawer's Introduction

react-native-scaling-drawer

React Native SwipeAble Scaling Drawer

Installation

npm i react-native-scaling-drawer --save

Demo Demo

API

Prop Type Default Description
scalingFactor number 0.6 Maximum scaling size (in percantage) of your Front View's scale. Set value higher than 0.1 lower than 1
minimizeFactor number 0.7 Maximum push offset (in percentage) of your Front View's position relative to left edge of screen. A value of 0.5 means middle of screen if scaling value is
content element - Drawer content menu(Left Menu)
swipeOffset number 10 Minimum offset for your Front View to trigger Drawer's Swipe action
contentWrapperStyle object - Drawer Menu Wrapper custom style
frontStyle object - Front View custom style
onOpen function - If u open drawer trigger onOpen function
onClose function - If u close drawer trigger onClose function

NOTE

If you want to disable drawer swipe, you can access blockSwipeAbleDrawer method and send true. (Default value false, you can swipe drawer any screen). You can check my example for block.

Example With React Navigation

import React, {Component} from 'react';
import {View, StatusBar, TouchableOpacity, Text} from 'react-native';
import ScalingDrawer from 'react-native-scaling-drawer';
import Home from './container/Home';
import Profile from './container/Profile';
import Wins from './container/Wins';
import Detail from './container/Detail';
import LeftMenu from './component/LeftMenu';
import {
  createNavigator,
  createNavigationContainer,
  StackRouter,
  addNavigationHelpers,
} from 'react-navigation';

let defaultScalingDrawerConfig = {
  scalingFactor: 0.6,
  minimizeFactor: 0.6,
  swipeOffset: 20
};

class CustomDrawerView extends Component {
  constructor(props) {
    super(props);
  }

  componentWillReceiveProps(nextProps) {
    /** Active Drawer Swipe **/
    if (nextProps.navigation.state.index === 0)
      this._drawer.blockSwipeAbleDrawer(false);

    if (nextProps.navigation.state.index === 0 && this.props.navigation.state.index === 0) {
      this._drawer.blockSwipeAbleDrawer(false);
      this._drawer.close();
    }

    /** Block Drawer Swipe **/
    if (nextProps.navigation.state.index > 0) {
      this._drawer.blockSwipeAbleDrawer(true);
    }
  }

  setDynamicDrawerValue = (type, value) => {
    defaultScalingDrawerConfig[type] = value;
    /** forceUpdate show drawer dynamic scaling example **/
    this.forceUpdate();
  };

  render() {
    const {routes, index} = this.props.navigation.state;
    const ActiveScreen = this.props.router.getComponentForState(this.props.navigation.state);

    return (
      <ScalingDrawer
        ref={ref => this._drawer = ref}
        content={<LeftMenu navigation={this.props.navigation}/>}
        {...defaultScalingDrawerConfig}
        onClose={() => console.log('close')}
        onOpen={() => console.log('open')}
      >
        <ActiveScreen
          navigation={addNavigationHelpers({
            ...this.props.navigation,
            state: routes[index],
            openDrawer: () => this._drawer.open(),
          })}
          dynamicDrawerValue={ (type, val) => this.setDynamicDrawerValue(type, val) }
        />
      </ScalingDrawer>
    )
  }
}

const AppNavigator = StackRouter({
  Home: {screen: Home},
  Profile: {screen: Profile},
  Wins: {screen: Wins},
  Detail: {
    screen: Detail,
    path: 'detail'
  }
}, {
  initialRouteName: 'Home',
});

const CustomDrawer = createNavigationContainer(createNavigator(AppNavigator)(CustomDrawerView));

export default CustomDrawer;

TODO

  • Add Perspective Animation

react-native-scaling-drawer's People

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  avatar  avatar  avatar  avatar

react-native-scaling-drawer's Issues

TextInput hides behind keyboard

when you use any screen containing textinput inside scaling drawer you can see that after clicking on textinput of that screen keyboard will overlap that textinput in android here I am attaching a clip regarding this if possible please help.

Thank you.

Screen.Recording.2021-06-25.at.5.03.05.PM.mov

Transition when navigate to other screen

this is very nice. react-native-scaling-drawer.
i loved it.
but i am having a isssue that they are using StackRouter.
and i want to have transition from right to Left when navigate to other screen.
i dont know how to have transition in StackRouter.

plz help me...

transitionconfig in stackRouter

Do you have an example where I can use these custom transitions inside a Custom navigator created using the createNavigationContainer(
createNavigator(AppStackRouter)(StackView)
);

This is based off of CustomTabs example in react-navigation examples. Here I am confused as to how do I pass my transitionConfig inside createNavigator.

here is how I defined my StackRouter( which seems to take the stackConfig which in turn seems to take a StackConfig param as per here .

export const AppStackRouter = StackRouter(defaultMap, {
initialRouteName: 'StartScreenView',
transitionConfig: TransitionConfiguration,
});

But still the console.log (), I wrote inside the screenInterpolator of the transitionConfig is not hit :(. Any thoughts on what I am doing wrong?

UPDATE 2:
Tried a different approach by passing the transition config to teh createNavigator 3rd argument
createNavigationContainer(
createNavigator(AppStackRouter, {}, {transitionConfig: TransitionConfiguration})(StackView)
);

still the console.log inside my screenInterpolator did not get hit . I am officially out of ideas now in trying to get animations to work inside a Custom navigator. I would expect the default stack animations would exist even if we create a custom stack navigator, but turns out it is not the case

Is there any way to use this with @react-navigation v5 ?

I'd like to use this package with @react-navigation v5 which is the latest version.
I am sure I am not the only one. My App.js looks like this - any suggestions?

import 'react-native-gesture-handler';
import React,{Component} from 'react';
import {AppState} from 'react-native';
import {connect} from 'react-redux';
import Home from './app/screens/Home/Home';
import ArtistListing from './app/screens/ArtistListing/ArtistListing';
import ArtPeriods from './app/screens/ArtPeriods/ArtPeriods';
import Login from './app/screens/Login/Login';
import Quiz from './app/screens/Quiz/Quiz';
import GuessWhen from './app/screens/GuessWhen/GuessWhen';
import { NavigationContainer, useLinking } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createDrawerNavigator } from '@react-navigation/drawer';
import {Auth, Hub} from 'aws-amplify';
import {GetUserFromDB, SetCurrentUser, SetLoggedOutUser} from './src/model/User';
import LearnMore from './app/screens/LearnMore/LearnMore';
import {CreateAllArtistsWithDependencies} from './src/model/Artists';
import ExploreTimePeriod from './app/screens/ExploreTimePeriod/ExploreTimePeriod';
import ExploreArtist from './app/screens/ExploreArtist/ExploreArtist';
import PhotoGalleryScreen from './app/screens/PhotoGalleryScreen/PhotoGalleryScreen';
import ExploreTimePeriods from './app/screens/ExploreTimePeriods/ExploreTimePeriods';
import ExploreArtists from './app/screens/ExploreArtists/ExploreArtists';
import QuizSummary from './app/screens/QuizSummary/QuizSummary';
import ContactUs from './app/screens/ContactUs/ContactUs';
import Profile from './app/screens/Profile/Profile';
import Favorites from './app/screens/Favorites/Favorites';
import Logout from './app/screens/Logout/Logout';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
function stackNavigation (){
    return (
        <Stack.Navigator>
            <Stack.Screen name="Home" component={Home} options={{headerShown:false}} />
            <Stack.Screen name="ArtistListing" component={ArtistListing} options={{headerShown:false}}/>
            <Stack.Screen name="ArtPeriods" component={ArtPeriods} options={{headerShown:false}}/>
            <Stack.Screen name="GuessWhen" component={GuessWhen} options={{headerShown:false}}/>
            <Stack.Screen name="Quiz" component={Quiz} options={{headerShown:false}}/>
            <Stack.Screen name="LearnMore" component={LearnMore} options={{headerShown:false}}/>
            <Stack.Screen name="ExploreTimePeriod" component={ExploreTimePeriod} options={{headerShown:false}}/>
            <Stack.Screen name="ExploreTimePeriods" component={ExploreTimePeriods} options={{headerShown:false}}/>
            <Stack.Screen name="PhotoGalleryScreen" component={PhotoGalleryScreen} options={{headerShown:false}}/>
            <Stack.Screen name="ExploreArtist" component={ExploreArtist} options={{headerShown:false}}/>
            <Stack.Screen name="ExploreArtists" component={ExploreArtists} options={{headerShown:false}}/>
            <Stack.Screen name="QuizSummary" component={QuizSummary} options={{headerShown:false}}/>
            <Stack.Screen name="ContactUs" component={ContactUs} options={{headerShown:false}}/>
            <Stack.Screen name="Profile" component={Profile} options={{headerShown:false}}/>
            <Stack.Screen name="Favorites" component={Favorites} options={{headerShown:false}}/>
        </Stack.Navigator>
    );
}
//adding the key currentUser to the props and setting it to the state's value of current user
const mapStateToProps = (state) => {
    return {
        currentUser: state.currentUser
    }
};
class App extends Component {

    constructor(props){
        super(props);
        Hub.listen("auth", ({ payload: { event, data } }) => {
            switch (event) {
                case "signIn":
                    SetCurrentUser();
                    break;
            }
        });
    }

    render() {
        return (
            <NavigationContainer>
                {this.props.currentUser.hasOwnProperty('username') ? <Drawer.Navigator>
                        <Drawer.Screen name="Take a Quiz" component={stackNavigation} unmountOnBlur={true} options={{headerShown: false, unmountOnBlur:true}}/>
                        <Drawer.Screen name="Profile" component={Profile} options={{headerShown: false}}/>
                        <Drawer.Screen name="Explore Time Periods" component={ExploreTimePeriods}
                                       options={{headerShown: false}}/>
                        <Drawer.Screen name="Discover Artists" component={ExploreArtists} options={{headerShown: false}}/>
                        <Drawer.Screen name="Favorites" component={Favorites} options={{headerShown: false}}/>
                        <Drawer.Screen name="Contact Us" component={ContactUs} options={{headerShown: false}}/>
                        <Drawer.Screen name="Logout" component={Logout} options={{headerShown: false}}/>
                    </Drawer.Navigator> :
                    <Stack.Navigator>
                        <Stack.Screen name="Login" component={Login} options={{headerShown: false}}/>
                    </Stack.Navigator>
                }
            </NavigationContainer>
        );
    }
};

export default connect(mapStateToProps)(App);

The height of the screen is bigger than the height of the mobile window

I'm using the newest version of react-native-scaling-drawer which is version 1.0.2 at the time of writing this issue and supports RTL movement and I encountered a problem. The problem is that the front view is not shown completely, It's like the height of the front view is bigger than the window itself.
As the following pictures demonstrate the blue line has been set out of the window's bound.

image

Untitled

This is my code:

<ScalingDrawer
    position="right"
    ref={drawer}
    content={
        <View style={{
            flex: 1,
            backgroundColor: 'pink',
        }}>
        </View>
    }
    {...defaultScalingDrawerConfig}
>
    <View style={{ flex: 1, backgroundColor: 'red' }}></View>
    <View style={{
        position: 'absolute',
        left: 0,
        right: 0,
        bottom: 0,
        backgroundColor: 'blue',
        height: 3,
    }}></View>

</ScalingDrawer >

I would appreciate it if you could fix this.
Thanks for your wonderful job.

Package version number

When I try to install react-native-scaling-drawer on version 1.0.2, I get the following error:

yarn add [email protected]
yarn add v1.13.0
warning ../../../package.json: No license field
[1/4] ๐Ÿ” Resolving packages...
Couldn't find any versions for "react-native-scaling-drawer" that matches "1.0.2"
? Please choose a version of "react-native-scaling-drawer" from this list: (Use arrow keys)
โฏ 1.0.1

Shouldn't we have 1.0.2 on the package.json file?:

{
"name": "react-native-scaling-drawer",
"version": "1.0.1",
...
}

Thanks!

Failed propType: SwipableDrawer

Hey thanks for the awesome library. Absolutely love it โค๏ธ

I tried it with React Navigation, its a little different than yours.

StackNavigator consisting of DrawerNavigator(this being replaced by StackRouter as shown in the example) & StackNavigator.

The complete question is posted on StackOverflow so I don't bloat here.

Not Working with react navigation 3

I am trying to use this drawer inside my application but i am using react-navigation version 3 and your drawer is no longer supported on v3

React Navigation (Version Issues)

there is react native navigation version issue. it is not working with new version of react-navigation

Cannot call a class as a function
_classCallCheck
index.delta?platform=android&dev=true&minify=false:64832:114
Navigator
index.delta?platform=android&dev=true&minify=false:64869:24

index.delta?platform=android&dev=true&minify=false:61590:121
loadModuleImplementation
index.delta?platform=android&dev=true&minify=false:159:14
guardedLoadModule
index.delta?platform=android&dev=true&minify=false:92:38
_require
index.delta?platform=android&dev=true&minify=false:73:79

index.delta?platform=android&dev=true&minify=false:61306:31
loadModuleImplementation
index.delta?platform=android&dev=true&minify=false:159:14
guardedLoadModule
index.delta?platform=android&dev=true&minify=false:92:38
_require
index.delta?platform=android&dev=true&minify=false:73:79

index.delta?platform=android&dev=true&minify=false:1426:22
loadModuleImplementation
index.delta?platform=android&dev=true&minify=false:159:14
guardedLoadModule
index.delta?platform=android&dev=true&minify=false:84:47
_require
index.delta?platform=android&dev=true&minify=false:73:79
global code
index.delta?platform=android&dev=true&minify=false:101645:8

How to use deeplink to change the inner screen

const AppStack = createStackNavigator({
Home: {
screen: HomeScreen, path: 'home/:id'
},
News: {
screen: LatestNewsScreen, path: 'news/:id'
},
Setting: {
screen: SettingScreen, path: 'setting/:id'
},
Registration: {
screen: RegistrationScreen, path: 'path/:id'
},
Race: {
screen: RaceScreen, path: 'race/:id'
}
}, {
initialRouteName: 'Home',
defaultNavigationOptions: ({ navigation }) => ({
header: null
})
});

<SwipeAbleDrawer
ref= { drawer }
content = {<MenuView drawer = { drawer } />}
{...Variables.defaultScalingDrawerConfig }
onClose = {() => this.onMenuClose()}
onOpen = {() => this.onMenuOpen()}
>
<AppContainer
ref={
navigatorRef => {
console.log("navRef", navigatorRef);
NavigationService.setTopLevelNavigator(navigatorRef);
}
}
uriPrefix={prefix}
/>

it cannot change the inner screen which used uriprefix

Not working when i use react-native-scaling-drawer

my react native version is:

"react-native": "0.64.2"

when i run yarn add react-native-scaling-drawer it shows error like

F:\Innovius\Sam>yarn add react-native-scaling-drawer
yarn add v1.22.10
[1/4] Resolving packages...
warning react-native-scaling-drawer > [email protected]: This version of React Navigation is no longer supported. Please upgrade to at least React Navigation 4.
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

can any one help?

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.