diff --git a/Example/Example.js b/Example/Example.js index a05341089..0500bfd10 100644 --- a/Example/Example.js +++ b/Example/Example.js @@ -10,6 +10,7 @@ import Home from './components/Home' import TabView from './components/TabView' import EchoView from './components/EchoView' import NavigationDrawer from './components/NavigationDrawer' +import Title from './components/Title'; import Button from "react-native-button"; class TabIcon extends React.Component { @@ -105,7 +106,10 @@ export default class Example extends React.Component { - + + + + diff --git a/Example/components/Launch.js b/Example/components/Launch.js index f369aeaa0..f9e34bf1d 100644 --- a/Example/components/Launch.js +++ b/Example/components/Launch.js @@ -24,6 +24,7 @@ class Launch extends React.Component { + diff --git a/Example/components/Title.js b/Example/components/Title.js new file mode 100644 index 000000000..ef104540f --- /dev/null +++ b/Example/components/Title.js @@ -0,0 +1,71 @@ +import React from 'react'; +import {View, Text, StyleSheet} from "react-native"; +import Button from "react-native-button"; +import {Actions} from "react-native-router-flux"; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: "center", + alignItems: "center", + backgroundColor: "#F5FCFF", + }, + welcome: { + fontSize: 20, + textAlign: "center", + margin: 10, + }, + instructions: { + textAlign: "center", + color: "#333333", + marginBottom: 5, + }, +}); + +export default class extends React.Component { + constructor() { + super(); + this.title = "Hello world!"; + + this.increaseTitleLength = this.increaseTitleLength.bind(this); + this.decreaseTitleLength = this.decreaseTitleLength.bind(this); + this.setNumberOfLines = this.setNumberOfLines.bind(this); + this.unsetNumberOfLines = this.unsetNumberOfLines.bind(this); + } + + render(){ + return ( + + Title page + + + + + + + + ); + } + + increaseTitleLength() { + this.title += "Hello World!"; + + Actions.refresh({title: this.title}); + } + + decreaseTitleLength() { + if(this.title.length > 12) { + this.title = this.title.slice(0, -12); + } + + Actions.refresh({title: this.title}); + } + + unsetNumberOfLines() { + Actions.refresh({titleNumberOfLines: null}); + } + + setNumberOfLines(numberOfLines) { + Actions.refresh({titleNumberOfLines: numberOfLines}); + } +} diff --git a/README.md b/README.md index 329a9bf62..d752d0cc8 100644 --- a/README.md +++ b/README.md @@ -121,4 +121,4 @@ And then: + Epic Fail Videos ([iOS](https://itunes.apple.com/us/app/epic-fail-videos-best-fail/id1115219339), [Android](https://play.google.com/store/apps/details?id=com.hazuu.epicfailvideos)) - The best Fail Videos Collection, never miss a laugh with your friends! ## Support -Thanks to all who submitted PRs to 2.x release. If you like the component and want to support it, feel free to donate any amount or help with issues. +Thanks to all who submitted PRs to 2.x release. If you like the component and want to support it, feel free to donate any amount or help with issues. \ No newline at end of file diff --git a/README2.md b/README2.md index 3f25b2532..fe2699541 100644 --- a/README2.md +++ b/README2.md @@ -49,6 +49,7 @@ npm i react-native-router-flux --save | hideTabBar | bool | false | hides tab bar for this route (if built-in TabBar component is used as footer for parent Router, check Example)| | navigationBarStyle | View style | | optional style override for the navigation bar | | titleStyle | Text style | | optional style override for the title element | +| titleNumberOfLines | `number` | optional | Number of lines the title should wrap before truncating with an ellipsis | | renderTitle | Closure | | optional closure to render the title element | | barButtonIconStyle | Image style | | optional style override for icon buttons (e.g. back icon) | | leftTitle | string | | optional string to display on the left if the previous route does not provide `renderBackButton` prop. `renderBackButton` > `leftTitle` > | diff --git a/docs/API_CONFIGURATION.md b/docs/API_CONFIGURATION.md index 7256e29e4..3c64ef8c7 100644 --- a/docs/API_CONFIGURATION.md +++ b/docs/API_CONFIGURATION.md @@ -67,6 +67,7 @@ | getTitle | `function` | optional | Optionally closure to return a value of the title based on state | | renderTitle | `function` | optional | Optionally closure to render the title | | titleStyle | [`Text style`](https://facebook.github.io/react-native/docs/text.html#style) | | optional style override for the title element | +| titleNumberOfLines | `number` | optional | Number of lines the title should wrap before truncating with an ellipsis | #### Navigation Bar: Back button | Property | Type | Default | Description | diff --git a/src/NavBar.js b/src/NavBar.js index 1629ea908..946e1ce40 100644 --- a/src/NavBar.js +++ b/src/NavBar.js @@ -120,6 +120,7 @@ const propTypes = { leftButtonIconStyle: Image.propTypes.style, getTitle: PropTypes.func, titleStyle: Text.propTypes.style, + titleNumberOfLines: PropTypes.number, position: PropTypes.object, navigationBarStyle: View.propTypes.style, renderTitle: PropTypes.any, @@ -324,6 +325,9 @@ class NavBar extends React.Component { renderTitle(childState, index:number) { const title = this.props.getTitle ? this.props.getTitle(childState) : childState.title; + const titleNumberOfLines = this.props.titleNumberOfLines; + const hasNumberOfLinesProp = Number.isInteger(titleNumberOfLines) && titleNumberOfLines >= 1; + return ( {title}