Single screen application without bottom navigation bar - react-native

I've analyzed the needs of my application and decided I can more efficiently develop it with mobile friendly components on the web and present it via a web view in an app.
I need permissions to access camera and gallery (to take photos / videos, and upload photos / videos).
Basically, a single-screen app with a webview presenting the site with mobile-friendly components and the above permissions.
This is my current app.js:
import React from 'react';
import { Button, Text, View, TouchableOpacity, StyleSheet } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import {
createStackNavigator,
createBottomTabNavigator,
createAppContainer,
} from 'react-navigation';
//import createStackNavigator, createBottomTabNavigator, createAppContainer in our project
import HomeScreen from './pages/HomeScreen';
import { Constants, Location, Camera, Permissions } from 'expo';
const ProfileStack = createStackNavigator(
{
//Definition of Navigaton from home screen
HomeScreen: { screen: HomeScreen },
},
{
//For React Navigation 2.+ change defaultNavigationOptions->navigationOptions
defaultNavigationOptions: {
//Header customization of the perticular Screen
headerStyle: {
backgroundColor: 'orange',
},
headerTintColor: '#FFFFFF',
title: '',
//Header title
},
}
);
const App = createBottomTabNavigator(
{
HomeScreen: { screen: HomeScreen },
},
{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
let IconComponent = Ionicons;
let iconName;
if (routeName === 'HomeScreen') {
iconName = `ios-information-circle${focused ? '' : '-outline'}`;
}
return <IconComponent name={iconName} size={25} color={tintColor} />;
},
}),
tabBarOptions: {
activeTintColor: 'orange',
inactiveTintColor: 'gray',
},
}
);
export default createAppContainer(App);
and './pages/HomeScreen':
//This is an example code for Bottom Navigation//
import React, {Component} from 'react';
//import react in our code.
import { Text, View, TouchableOpacity, StyleSheet, WebView } from 'react-native';
//import all the basic component we have used
export default class ProfileScreen extends React.Component {
//Profile Screen to show from Open profile button
render() {
return (
<WebView
source={{uri: 'https://mobilesite'}}
style={{marginTop: 20}}
/>
);
}
}
So far, the site opens on a single screen as expected, but there's a bottom navigation bar present; I'd also like to preferably hide the top bar if possible too as I've accounted for that in a mobile-friendly header on the mobile site as well.
Also, via the mobile web codebase, I'm utilizing <input type="file" /> for uploading. Is this compatible with React Native Permissions?

You're using createBottomTabNavigator() and passing the resulting navigator to your createAppContainer() which will create a bottom tab navigator.
If you pass a StackNavigator (via createStackNavigator() which you use for ProfileStack) to the createAppContainer() it'll render the stack as opposed to the bottom tab navigator which is what you want.
To remove the header altogether you can use headerMode: 'none' in the navigationOptions param.
You can see a basic version of what you want here (sans the lack of a header) in the React Navigation docs.

Related

How to add splashscreen?

I want to add a splashscreen to my code before the HomeScreen comes.
This is my new Splashscreen.js file
import React from 'react';
import { StatusBar, View, Text, ActivityIndicator } from 'react-native';
import HomeScreen from './screens/HomeScreen.js';
export default class SplashScreen extends React.Component {
render() {
return(
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#34495e'}}>
<StatusBar backgroundColor="#2c3e50" barStyle="light-content" />
<Text style={{ color: 'white', fontSize: 18}}>WELCOME</Text>
<ActivityIndicator color={'white'} />
</View>,
);
}
}
This is my new App.js file
import React, {Component} from 'react';
import { Keyboard, Alert } from 'react-native';
import {createAppContainer, createStackNavigator} from 'react-navigation';
import HomeScreen from './screens/HomeScreen.js';
/** Importing navigator */
import AppDrawerNavigator from './drawerNavigator';
/** Redux **/
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import SplashScreen from './screens/SplashScreen.js';
const initialState = {
username: null,
password: null,
};
const reducer = (state=initialState, action) => {
if(action.type) {
console.log('NEW',action.name);
}
return {state, username: action.name, password: action.pass};
}
const store = createStore(reducer);
class App3 extends React.Component {
componentWillMount() {
this.state = {
view: <SplashScreen />
};
setTimeout(() => {
this.setState({
view: <HomeScreen />
})
}, 2000)
}
render() {
return (
// this.state.view,
<Provider store = {store}>
<AppContainer />
</Provider>
);
}
}
export default App3;
const AppStackNavigator = createStackNavigator(
{
Home: {
screen: HomeScreen
},
Welcome: {
screen: AppDrawerNavigator
}
},
{
initialRouteName: 'Home',
headerMode: "none",
}
);
const AppContainer = createAppContainer(AppStackNavigator);
If you want to check my other screens and files you can check this link.
I want to add the splashscreen file I created to my existing code without affecting the exisiting functionality. I want to achieve the following things:
Open application
Show splashscreen for a sec.
Go to login screen if not logged in before otherwise go to Welcomescreen directly from splashscreen
I would recommend you to take a look at Spencer Cali medium article. It covers adding a splash screen for RN apps step by step. How to Add a Splash Screen to a React Native App (iOS and Android)
For react-native you do not need to create file for splash screen.
just follow bellow package for splash screen i suggest you that is very good library with lots of users and yes i'm always prefer this library for splash screen.
you just need to create image for the splash screen whatever you want to show upon user on initial.
react-native-splash-screen
you may find all detail here and follow it step by step it will help you.
it always help for me!
Splash screen and loading screen are different. The splash screen is shown when application is open from termination status.
After that, some applications show loading screens for processing background logics as like checking user signin, get datas and so on.
In you case, you looks to show loading screen for authentication flows.
Use this ways.
React Navigation Auth flows
This flow is as below.
Show loading screen and check the user auth
navigate to another screen according to auth result.
if (loggedIn) { this.props.navigation.navigate('SignUpScreen') }
else { this.props.navigation.navigate('HomeScreen') }
Happy!
And if you want to use splash screen, not loading screen, I recommend to use rn-toolbox.

How to change header title dynamically

I built a React Native app which has 2 tabs for change screen. When I change a screen I would like to change also the title of the header. So when I press Tab 1 the tile is Tab 1 and Tab 2 if Tab 2 screen is on.
I would like to understand what kind of change or add I need to do to perform that action in my code. Iùm sharing the code where I think should be done the change but if Iùm wrong please guide me to the right code I should share. I'm new to Native and I'm trying to learn it.
I have a Route.js file:
import React from 'react';
import { View, Platform, Image, StyleSheet } from "react-native";
import {createStackNavigator} from "react-navigation";
import FlightsTabNavigator from "./App/navigations/FlightsTabNavigator";
import FlightsHeader from "./App/components/header/FlightsHeader";
import HeaderStyle from "./App/styles/HeaderStyle";
import s from "./App/styles/headerImgStyle";
const Routes = createStackNavigator({
FlightsTabNavigator: {
screen: FlightsTabNavigator,
}
},{
initialRouteName: 'FlightsTabNavigator',
navigationOptions: {
headerTitle: '',
headerBackground: (
<Image
style={s.image}
//source={require('./App/assets/header/header.jpg')}
source={{uri: 'https://images.unsplash.com/photo-1503365113766-4a362681eac5?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=79cf794378a008ab1d74b8e612d72ad0&auto=format&fit=crop&w=1050&q=80'}}
/>
),
header: props => <FlightsHeader {...props} />,
...HeaderStyle,
animationEnabled: true
}
});
export default Routes;
And the Header:
import React from "react";
import { Header } from "react-navigation";
import { View, Text, Platform, Image, StyleSheet } from "react-native";
const FlightsHeader = props => {
return (
<View>
<Header {...props} />
</View>
);
};
export default FlightsHeader;

React Native Connect Three or More Screen using for react navigation

how to connect three or more screen in react native for Android and using react navigator.
Your question is quite unclear and and I can only assume what you want to achieve.
To be sure that we are on the same page, make sure you have run this command npm install --save react-navigation inside your project root directory.
Now in your app.js file you have to import StackNavigator from React-Navigation.
import { StackNavigator } from 'react-navigation';
Then you should import your screen components which later can be added to StackNavigator. For the sake of this example I import random files with random names. You wanted three and more, so let's import four.
import HomeScreen from './screens/HomeScreen';
import ProfileScreen from './screens/ProfileScreen';
import NewsScreen from './screens/NewsScreen';
import SettingsScreen from './screens/SettingsScreen';
All these files are located in the screens folder which itself is located in the same folder as app.js file. Now let's create our StackNavigator. These next lines go inside the app.js.
const NavigationApp = StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
News: { screen: NewsScreen },
Settings: { screen: SettingsScreen }
})
Now your app.js file should look like this.
import React, { Component } from 'react';
import { StackNavigator } from 'react-navigation';
import HomeScreen from './screens/HomeScreen';
import ProfileScreen from './screens/ProfileScreen';
import NewsScreen from './screens/NewsScreen';
import SettingsScreen from './screens/SettingsScreen';
const NavigationApp = StackNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
headerTitle: 'Home'
}
},
Profile: { screen: ProfileScreen},
News: { screen: NewsScreen},
Settings: { screen: SettingsScreen}
})
export default class App extends Component {
render() {
return (
<NavigationApp />
);
}
}
Just in case to be super certain that you would get the full experience of our epic journey let's create one example screen with button which would let us navigate to another screen. Let's say it's Home and we have a button which would let us navigate to Profile.
import React, { Component } from 'react';
import { View, TouchableOpacity, Text } from 'react-native';
export default class HomeScreen extends Component {
render() {
const { navigate } = this.props.navigate
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TouchableOpacity style={{color: 'steelblue'}} onPress={() => navigate('Profile')}>
<Text style={{fontSize: 12, color: 'white', padding: '10'}}>
Go to Profile screen
</Text>
</TouchableOpacity>
</View>
);
}
}
I hope this helps you to move on with your project and I really recommend to dive into the documentations of the libraries you will be using in the future because in the long run it is very useful and helps you get better in many aspects.

React-navigation 'Home' should declare a screen

I'm trying to get a handle on react-navigation by making a dead simple app; I just want two screens with buttons you can click on to go between them. Here's my code:
App.js:
import React from 'react';
import {
Text,
View,
Button
} from 'react-native';
import {
StackNavigator,
} from 'react-navigation';
import OtherPage from './OtherPage';
const Home = ({navigation}) => (
<View>
<Text style={styles.title}>Welcome</Text>
<Button title="Other Page" onPress={() => {
navigation.navigate('OtherPage')
}}></Button>
</View>
);
const Nav = StackNavigator(
{
OtherPage: { screen: OtherPage},
Index: {
screen: Home
}
},
{
initialRouteName: 'Index',
}
);
export default () => <Nav />;
OtherPage.js:
import React from 'react';
import {
Text,
View,
Button
} from 'react-native';
import { StackNavigator } from 'react-navigation';
const OtherPage = ({navigation}) => (
<View>
<Text>Other Page</Text>
<Button title="Go Home" onPress={() => {
navigation.navigate('Home');
}}></Button>
</View>
);
import Home from './App';
const Nav = StackNavigator(
{
OtherPage: { screen: OtherPage},
Home: { screen: Home }, // THIS LINE CAUSES THE ERROR
},
);
export default () => <Nav />;
For some reason what I get back from import Home from './App'; isn't a screen and so I get the error Route 'Home' should declare a screen. It's definitely that line that's causing the problem, if I comment it out then the app loads and I can click the button on the home screen to go to the other page, but then of course I'm stuck there and can't go back.
What's confusing me is that these files are essentially identical in how everything's declared, and for some reason import OtherPage from './OtherPage'; is a valid screen but import Home from './App'; isn't.
Can anyone help me out? What am I doing wrong?

Toggling a drawer from header icon using react-navigation

I am new to react-native and react-navigation.
Required Screen: A home page with a header (Thumbnail + title) , two tabs and a drawer that toggles onPress of the thumbnail.
Please check my code:
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import {Icon, Button} from 'native-base';
const util = require('util');
import { TabNavigator, StackNavigator, DrawerNavigator, NavigationActions } from 'react-navigation';
import FirstScreen from './tabs/FirstScreen';
import SecondScreen from './tabs/SecondScreen';
import Profile from './Profile';
import SearchScreen from './tabs/SearchScreen';
const DrawerScreens = DrawerNavigator({
Profile: {screen: Profile}
},{
drawerPosition: 'left',
drawerWidth: 150
});
// A drawer navigator
const TabScreens= TabNavigator({
First: {screen: FirstScreen},
Second: {screen: SecondScreen}
});
// Started with a tab navigator to register two tabs
const MenuButton =({navigation})=>{
return(
<View>
<TouchableOpacity onPress={()=>(navigation.navigate('DrawerToggle'))}>
<Icon name="person" size= {20}/>
</TouchableOpacity>
</View>)};
export const StackScreens= StackNavigator({
Draw: {screen: DrawerScreens},
// Drawer navigator as a screen
Display: {screen: TabScreens,
// Making the tabnavigator as a screen
navigationOptions: ({navigation})=>({
title: 'Welcome',
headerLeft: <MenuButton navigation={navigation} />
})
},
},{
initialRouteName: 'Display'
});
On pressing of the thumbnail the TabScreens navigates to the DrawerScreens (since that is how i coded). I want to make it toggle. Can someone please help me.
Here's some general ideas on how to structure your navigator properly.
What react-navigation version are you using?
Try changing your MenuButton helper method to this and see if it helps
if (navigation.state.index === 0) {
navigation.navigate('DrawerOpen')
} else {
navigation.navigate('DrawerClose')
}