Coder Social home page Coder Social logo

jineshshah36 / react-native-nav Goto Github PK

View Code? Open in Web Editor NEW
264.0 6.0 28.0 764 KB

A cross-platform (iOS / Android), fully customizable, React Native Navigation Bar component.

License: MIT License

JavaScript 100.00%
react-native react android ios navigation navbar

react-native-nav's Introduction

No Longer Maintained

I wrote this very early when react native was also very new. I no longer recommend using this library. Please consider using a solution like react-navigation.

A cross-platform (iOS / Android), fully customizable, React Native Navigation Bar component.

I created this project after going through the navbars contained in Awesome React and not finding any that were cross-platform, customizable, and integrated the status bar. This project is a spiritual successor to react-native-navbar (I forked it and ended up changing like 90% of it).

To find a preview of all examples go to the examples folder.

Note

This library of components require the use of React Native's Babel transpiler to work. If you are using the most up to date version of React Native, it should just work out of the box.

preview

Content


Installation

First of all, make sure you're using [email protected]+ and [email protected]+ for version 1.1.1 or above. For version 2.0.0 and above, you will need to be using [email protected] or greater.

npm install --save react-native-nav

Getting started

Start a new React Native Project. Then, npm install --save react-native-nav.

iOS
import React, { Component } from 'react-native'
import NavBar, { NavButton, NavButtonText, NavTitle } from 'react-native-nav'

export default class NavBarIOSLight extends Component {
  render() {
    return (
      <NavBar>
        <NavButton onPress={() => alert('hi')}>
          <NavButtonText>
            {"Button"}
          </NavButtonText>
        </NavButton>
        <NavTitle>
          {"App"}
        </NavTitle>
        <NavButton onPress={() => alert('hi')}>
          <NavButtonText>
            {"Button"}
          </NavButtonText>
        </NavButton>
      </NavBar>
    )
  }
}
Android
import React, { Component } from 'react-native'
import NavBar, { NavGroup, NavButton, NavButtonText, NavTitle } from 'react-native-nav'

export default class NavBarAndroidLight extends Component {
  render() {
    return (
      <NavBar>
        <NavTitle>
          {"App"}
        </NavTitle>
        <NavGroup>
          <NavButton onPress={() => alert('hi')}>
            <NavButtonText>
              {"Button"}
            </NavButtonText>
          </NavButton>
          <NavButton onPress={() => alert('hi')}>
            <NavButtonText>
              {"Button"}
            </NavButtonText>
          </NavButton onPress={() => alert('hi')}>
          <NavButton>
            <NavButtonText>
              {"Button"}
            </NavButtonText>
          </NavButton>
        </NavGroup>
      </NavBar>
    )
  }
}

API

NavBar

The NavBar component is the main wrapper of all the other components. It creates the base navigation bar in iOS and Android and includes the StatusBar. You can pass any valid React Element or set of elements into it, making it very configurable.

To use it:

import NavBar from 'react-native-nav'

<NavBar>
  // Pass any React element(s) here
</NavBar>
Props

style

The best option is to use the Stylesheet object in React Native to create your styles

style = StyleSheet.create({
  statusBar: {
    // StatusBar styles here (all view styles are valid)

    // default iOS styles:
    height: IOS_STATUS_BAR_HEIGHT,
    backgroundColor: '#f5f5f5',

    // default Android styles:
    height: ANDROID_STATUS_BAR_HEIGHT,
    backgroundColor: '#f5f5f5',
  },
  navBarContainer: {
    // NavBarContainer styles here (all view styles are valid)
    // unlikely that you will need to add any styles here
  },
  navBar: {
    // NavBar styles here (all view styles are valid)

    // default shared styles:
    borderTopWidth: 0,
    borderBottomColor: 'rgba(0, 0, 0, 0.1)',
    borderBottomWidth: 1,
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',

    // default iOS styles:
    backgroundColor: '#f5f5f5',
    height: IOS_NAV_BAR_HEIGHT,
    paddingLeft: 8,
    paddingRight: 8,

    // default Android styles:
    backgroundColor: '#f5f5f5',
    height: ANDROID_NAV_BAR_HEIGHT,
    padding: 16,
  }
})

statusBar

This is using the default StatusBar in React Native. It shares the same set of props that you can override.

StatusBarConfig = {
  // put any configuration for the StatusBar here

  // default iOS configuration:
  animated: true,
  hidden: false,
  barStyle: 'default',
  networkActivityIndicatorVisible: false,
  showHideTransition: 'fade',

  // default Android configuration:
  animated: true,
  hidden: false,
  showHideTransition: 'fade',
  backgroundColor: 'rgba(0, 0, 0, 0.2)',
  translucent: true,  // I recommend you leave this true by default and
                      // set the backgroundColor to a non-translucent
                      // color if you don't want translucency
}

Note

The StatusBar props allow you to edit the backgroundColor for only the Android StatusBar. You can set a backgroundColor on it that is or isn't translucent. from within the configuration. You can also style it by passing a backgroundColor to styles.statusBar above. Setting the backgroundColor from the style will allow you to achieve cross-platform statusBar background color change.

NavTitle (optional)

The NavTitle component is a Text-based component that produces a nicely styled component for titles. Note: you don't have to use the NavTitle component. Since you can put any React Element in the NavBar, you could use an image or any other element, including the default Text component.

To use it:

import { NavTitle } from 'react-native-nav'

<NavTitle>
  {"My App"}
</NavTitle>
Props

style

The best option is to use the Stylesheet object in React Native to create your styles

style = StyleSheet.create({
  title: {
    // NavTitle styles here (all text styles are valid)

    // default styles:
    fontSize: 17,
    letterSpacing: 0.5,
    color: '#626262',
    fontWeight: '500',
    textAlign: 'center',
  },
})

NavButton (optional)

The NavButton component is a TouchableOpacity-based component that includes an onPress handler for performing actions when pressed. In general, react-native-nav is very flexible and should be easy to configure with just about any flux-like architecture such as flux and redux. You should be able to pass any method to the onPress handler such as a redux action.

In addition, the NavButton object can have any valid React component or set of components passed into it as children. You can use the NavButtonText component, but if you want to pass it an image, you can do that too.

To use it:

import { NavButton } from 'react-native-nav'

<NavButton>
  // Pass any React element(s) here
</NavButton>
Props

disabled

Setting this to true will disable the button and use the disabledStyle to style the button.

<NavButton disabled>
  // Pass any React element(s) here
</NavButton>

style

The best option is to use the Stylesheet object in React Native to create your styles.

style = StyleSheet.create({
  title: {
    // NavButton styles here (all view styles are valid)

    // default iOS styles:
    marginLeft: 0,

    // default Android styles:
    marginLeft: 16,
  },
})

disabledStyle

The best option is to use the Stylesheet object in React Native to create your styles.

style = StyleSheet.create({
  title: {
    // disabled NavButton styles here (all view styles are valid)

    // no default styles
  },
})

onPress

onPress takes a function that will be executed when the button is pressed. Example:

<NavButton onPress={() => alert('Hi!')}>
  <NavButtonText>
    {"Say Hi!"}
  </NavButtonText>
</NavButton>

NavButtonText (optional)

The NavButtonText component is a Text-based component that provides an easy wrapper for text buttons. However, the NavButton object can have any valid React element set of elements as its children, so you don't have to use this component.

To use it:

import { NavButtonText } from 'react-native-nav'

<NavButtonText>
  {"Button"}
</NavButtonText>
Props

style

The best option is to use the Stylesheet object in React Native to create your styles

style = StyleSheet.create({
  title: {
    // NavButtonText styles here (all text styles are valid)

    // default styles:
    fontSize: 17,
    letterSpacing: 0.5,
    color: '#939393',
  },
})

NavGroup (optional)

The NavGroup component is a View-based component that provides an easy wrapper for grouping a set of components. It can group all optional components in this library as well as any other valid React component. The main use case for NavGroup is when, for example on Android, you want a NavTitle on the left side and many NavButtons on the right side.

To use it:

import { NavGroup } from 'react-native-nav'

<NavGroup>
  // Pass any React element(s) here
</NavGroup
Props

style

The best option is to use the Stylesheet object in React Native to create your styles

style = StyleSheet.create({
  title: {
    // NavGroup styles here (all text styles are valid)

    // default styles:
    flexDirection: 'row',
  },
})

Examples

To find a preview of all examples go to the examples folder.

Questions?

Feel free to contact me via

License

The MIT License (MIT)

Copyright (c) 2015 Jinesh Shah

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

react-native-nav's People

Contributors

brunsy avatar cooperka avatar donnguyen avatar exoer avatar jineshshah36 avatar mariostasos 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

react-native-nav's Issues

Update to RN 0.25 to avoid deprecation warning

Than you for great components. It would be good if the import statements were updated to comply with react native 0.25 so that we avoid the deprecation warnings.

Let me know if you want me to do it and submit a pull request.

import React from 'react';

import {
    Text,
    View,
    StyleSheet,
} from 'react-native';

Nav title not centered

When buttons are of different width, title is no longer centered. See

        <NavBar>
          <NavButton onPress={() => alert('hi')}>
            <NavButtonText>
              Button
            </NavButtonText>
          </NavButton>
          <NavTitle>Title</NavTitle>
          <NavButton>
          <NavButtonText>
          B
          </NavButtonText>
          </NavButton>
        </NavBar>

image

Also, what If I just want a single title without any buttons?

        <NavBar>
          <NavTitle>Title</NavTitle>
        </NavBar>

I get this instead of the desired center behavior

image

Correct way of making a dynamic NavBar

Hi,
I've overridden the static renderNavigationBar() function in order to change the NavBar when a certain component - a form - is in focus.

What I actually want to do is make the form change the NavBar components in a dynamic way while going through different parts of it:

static renderNavigationBar(){
        console.log("in renderNavigationBar");
        return(
            <NavBar rightText="Next"
                    rightOnClick={()=>alert(this.state.name)}/>
        );
    }

rightText and rightOnClick are props I've added to my NavBarIOSLight implementation (similar to what is provided in the examples here).

The problem with my above code, is that this.state.name are obviously non-static members, so this won't work! What do you suggest is the best way to change the NavBar dynamically?

Thanks,
IY

NavTitle allowFontScaling

I'm using this component in a cross platform application, and I'm having the issue when the user changes the font size globally in the phone. I'm able to set the allowFontScaling={false} to Text components, but there's no direct way to do it for the NavTitle component.
The only way I found is to edit the code in the file eact-native-nav/components/NavTitle.js to add the property to the Text component inside.

Is there any other recommended way?

How can I make back button on Android ActionBar?

Hi,
I want to make a button on the left of page title so that user can go back to prev page.

<NavBar>
    <NavButton></NavButton>
    <NavTitle>{"HI"}</NavTitle>
</NavBar>

This code will position the page title to the right side of monitor.
But I want to place page title right by right of button.

How can I do that?

Inconsistent behaviour statusBar iOS

Problem

I have set the statusBar to always be visible, however, I have had some inconsistent behaviour from an iOS device:

  • When I start my app in portrait orientation, the statusBar is visible.
  • When I turn it to landscape, the statusBar is hidden, but the statusBar component itself is visible, giving the header a waterhead.

  • When I start my app in landscape orientation, the statusBar is visible.
  • When I turn it to portrait, the statusBar is also visible.

Expected behaviour

The statusBar should always be visible, as I have set it to always be visible.

Additional information

Version: 2.0.2
Platform: iOS (iPhone 6)
React Native version: 0.52.0

Code snippets/examples

I am currently unable to provide a code snippet or an example, but I'll try my best to provide it, if it is needed.

#Note

  • I don't know if I am using the right terminology for statusBar, but with that I mean the actual bar of the phone itself, with indicator icons and the current time.

android下 在 NavBar中没法使用TextInput

以下代码TextInput无法正常显示

<NavBar style={navBarStyles}>                
    <NavTitle>
        {"App"}
    </NavTitle>
    <NavGroup style={navBarStyles.navGroup}>
        <View>
            <TextInput
                ref={ref => this.textInput = ref}                            
                style={[defaultStyles.textInput]}
                />
        </View>
    </NavGroup>
</NavBar>

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.