1593325860
Setting up side drawer is quite straightforward in navigation component. First of all, create a menu resource file with necessary menu items. Here is how my main_menu.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/home_fragment"
android:title="Home" />
<item
android:id="@+id/terms_fragment"
android:title="Terms and Condition" />
</menu>
Note: The id of items in menu should be same as the fragment id in your main_navigation.xml. For eg:
<fragment
android:id="@+id/home_fragment"
android:name="com.rumi.toolbardrawerlayoutdemo.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home"/>
Next, in your **activity_main.xml **add the drawer layout. Couple of things we need to consider while creating the layout are:
<script src="https://gist.github.com/RumiRajbhandari/f00ff6f84b70f77aa47998c6d155f3b8.js"></script>
Now, in the **MainActivity.kt **we need to configure appBar. For that, we have to use appBarConfiguration which allows us to declare topLevelDestination and the drawerLayout. Top level destination represents root level destination which does not display back arrow in the action bar. Instead it displays the drawer icon if navigation drawer is setup. Pressing the back button in your keypad from top level destination will cause your application to exit.
appBarConfiguration = AppBarConfiguration(
setOf(R.id.home_fragment, R.id.cart_fragment),
binding.drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
NavigationUI.setupActionBarWithNavController performs following tasks:
Note: Make sure your jvmTarget version is 8 in your app level gradle file.
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
You can now see the drawer icon in your top-level destinations. However, if you click on it, the drawer layout does not appear. But you can swipe from the left side of the screen to view the drawer layout. NavigationUI will automatically handle the menu item click and will navigate to the respective fragment.
Now, in order to handle drawer icon click we need to override onSupportNavigateUp method.
override fun onSupportNavigateUp(): Boolean {
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
}
It will result in:
And that’s all it takes to setup drawer layout in android navigation. We no longer need to manually handle menuItem click and drawer toggling.
#navigation-component #bottomnavigationview #androiddev #kotlin #android
1594769040
This is an example of Bottom Tab View inside Navigation Drawer / Sidebar with React Navigation in React Native. We will use react-navigation to make a navigation drawer and Tab in this example. I hope you have already seen our post on React Native Navigation Drawer because in this post we are just extending the last post to show the Bottom Tab View inside the Navigation Drawer.
In this example, we have a navigation drawer with 3 screens in the navigation menu and a Bottom Tab on the first screen of the Navigation Drawer. When we open Screen1 the Bottom Tab will be visible and on the other options, this Bottom Tab will be invisible.
<NavigationContainer>
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: { marginVertical: 5 },
}}>
<Drawer.Screen
name="HomeScreenStack"
options={{ drawerLabel: 'Home Screen Option' }}
component={HomeScreenStack} />
<Drawer.Screen
name="SettingScreenStack"
options={{ drawerLabel: 'Setting Screen Option' }}
component={SettingScreenStack} />
</Drawer.Navigator>
</NavigationContainer>
<Tab.Navigator
initialRouteName="HomeScreen"
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
style: {
backgroundColor: '#e0e0e0',
},
labelStyle: {
textAlign: 'center',
fontSize: 16
},
}}>
<Tab.Screen
name="HomeScreen"
component={HomeScreen}
options={{
tabBarLabel: 'Home Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="home" color={color} size={size} />
// ),
}} />
<Tab.Screen
name="ExploreScreen"
component={ExploreScreen}
options={{
tabBarLabel: 'Explore Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="settings" color={color} size={size} />
// ),
}} />
</Tab.Navigator>
In this example, we will make a Tab Navigator inside a Drawer Navigator so let’s get started.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli
command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
If you want to start a new project with a specific React Native version, you can use the --version argument:
react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next
This will make a project structure with an index file named App.js in your project directory.
#bottom navigation #drawer navigation #react #react navigation
1593325860
Setting up side drawer is quite straightforward in navigation component. First of all, create a menu resource file with necessary menu items. Here is how my main_menu.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/home_fragment"
android:title="Home" />
<item
android:id="@+id/terms_fragment"
android:title="Terms and Condition" />
</menu>
Note: The id of items in menu should be same as the fragment id in your main_navigation.xml. For eg:
<fragment
android:id="@+id/home_fragment"
android:name="com.rumi.toolbardrawerlayoutdemo.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home"/>
Next, in your **activity_main.xml **add the drawer layout. Couple of things we need to consider while creating the layout are:
<script src="https://gist.github.com/RumiRajbhandari/f00ff6f84b70f77aa47998c6d155f3b8.js"></script>
Now, in the **MainActivity.kt **we need to configure appBar. For that, we have to use appBarConfiguration which allows us to declare topLevelDestination and the drawerLayout. Top level destination represents root level destination which does not display back arrow in the action bar. Instead it displays the drawer icon if navigation drawer is setup. Pressing the back button in your keypad from top level destination will cause your application to exit.
appBarConfiguration = AppBarConfiguration(
setOf(R.id.home_fragment, R.id.cart_fragment),
binding.drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
NavigationUI.setupActionBarWithNavController performs following tasks:
Note: Make sure your jvmTarget version is 8 in your app level gradle file.
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
You can now see the drawer icon in your top-level destinations. However, if you click on it, the drawer layout does not appear. But you can swipe from the left side of the screen to view the drawer layout. NavigationUI will automatically handle the menu item click and will navigate to the respective fragment.
Now, in order to handle drawer icon click we need to override onSupportNavigateUp method.
override fun onSupportNavigateUp(): Boolean {
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
}
It will result in:
And that’s all it takes to setup drawer layout in android navigation. We no longer need to manually handle menuItem click and drawer toggling.
#navigation-component #bottomnavigationview #androiddev #kotlin #android
1596321960
This is an example of Tab View inside Navigation Drawer / Sidebar with React Navigation in React Native. We will use react-navigation to make a navigation drawer and Tab in this example. I hope you have already seen our post on React Native Navigation Drawer because in this post we are just extending the last post to show the Tab View inside the Navigation Drawer.
In this example, we have a navigation drawer with 3 screens in the navigation menu and a Tab View on the first screen of the Navigation Drawer. When we open Screen1 the Tab will be visible and on the other options, this Tab will be invisible.
<NavigationContainer>
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: { marginVertical: 5 },
}}>
<Drawer.Screen
name="HomeScreenStack"
options={{ drawerLabel: 'Home Screen Option' }}
component={HomeScreenStack} />
<Drawer.Screen
name="SettingScreenStack"
options={{ drawerLabel: 'Setting Screen Option' }}
component={SettingScreenStack} />
</Drawer.Navigator>
</NavigationContainer>
<Tab.Navigator
initialRouteName="HomeScreen"
tabBarOptions={{
activeTintColor: '#FFFFFF',
inactiveTintColor: '#F8F8F8',
style: {
backgroundColor: '#f4511e',
},
labelStyle: {
textAlign: 'center',
},
indicatorStyle: {
borderBottomColor: '#87B56A',
borderBottomWidth: 2,
},
}}>
<Tab.Screen
name="HomeScreen"
component={HomeScreen}
options={{
tabBarLabel: 'Home Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="home" color={color} size={size} />
// ),
}} />
<Tab.Screen
name="ExploreScreen"
component={ExploreScreen}
options={{
tabBarLabel: 'Explore Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="settings" color={color} size={size} />
// ),
}} />
</Tab.Navigator>
In this example, we will make a Tab Navigator inside a Drawer Navigator so let’s get started.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli
command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
If you want to start a new project with a specific React Native version, you can use the --version argument:
react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next
This will make a project structure with an index file named App.js in your project directory.
## Installation of Dependencies
To install all the dependencies open the terminal and jump into your project
cd ProjectName
Run the following commands
npm install @react-navigation/native --save
npm install @react-navigation/drawer --save
npm install @react-navigation/stack --save
npm install @react-navigation/material-top-tabs react-native-tab-view --save
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view --save
This command will copy all the dependencies into your node_module directory. –save is optional, it is just to update dependencies in your package.json file.
## CocoaPods Installation
After the updation of React Native 0.60, they have introduced [autolinking](https://aboutreact.com/react-native-autolinking/) so we do not require to link the library but need to install pods. So to install pods use
npx pod-install ios
## Project Structure
To start with this example you need to create a directory named **pages** in your project and create three files ExploreScreen.js, HomeScreen.js, and SettingScreen.js.
These files will be the Navigation Screens of the Drawer Navigator.
## Code
Now Open App.js in any code editor and replace the code with the following code
### App.js
#how to #drawer navigation #tab navigation #react
1642781638
Bottom Drawer for Flutter
Bottom Drawer.
dependencies:
bottom_drawer: ^0.0.3
import 'package:bottom_drawer/bottom_drawer.dart';
Create a bottom drawer controller.
/// create a bottom drawer controller to control the drawer.
BottomDrawerController controller = BottomDrawerController();
Build a bottom drawer widget.
/// return a bottom drawer widget.
Widget buildBottomDrawer(BuildContext context) {
return BottomDrawer(
/// your customized drawer header.
header: Container(),
/// your customized drawer body.
body: Container(),
/// your customized drawer header height.
headerHeight: 60.0,
/// your customized drawer body height.
drawerHeight: 180.0,
/// drawer background color.
color: Colors.lightBlue,
/// drawer controller.
controller: controller,
);
}
Control the bottom drawer.
/// open the bottom drawer.
controller.open();
/// close the bottom drawer.
controller.close();
For more information, see the example.
Run this command:
With Flutter:
$ flutter pub add bottom_drawer
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
dependencies:
bottom_drawer: ^0.0.4
Alternatively, your editor might support flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:bottom_drawer/bottom_drawer.dart';
import 'package:bottom_drawer/bottom_drawer.dart';
import 'package:flutter/material.dart';
/// Created by GP
/// 2020/11/25.
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Bottom drawer example app'),
),
body: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Pressed $_button'),
Padding(
padding: EdgeInsets.only(top: 30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: Icon(
Icons.arrow_upward,
color: Colors.black,
),
onPressed: () {
_controller.open();
setState(() {
_button = 'Open Drawer';
});
},
),
Divider(
height: 10.0,
),
IconButton(
icon: Icon(
Icons.arrow_downward,
color: Colors.black,
),
onPressed: () {
_controller.close();
setState(() {
_button = 'Close Drawer';
});
},
),
],
),
),
],
),
_buildBottomDrawer(context),
],
),
),
);
}
Widget _buildBottomDrawer(BuildContext context) {
return BottomDrawer(
header: _buildBottomDrawerHead(context),
body: _buildBottomDrawerBody(context),
headerHeight: _headerHeight,
drawerHeight: _bodyHeight,
color: Colors.lightBlue,
controller: _controller,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.15),
blurRadius: 60,
spreadRadius: 5,
offset: const Offset(2, -6), // changes position of shadow
),
],
);
}
Widget _buildBottomDrawerHead(BuildContext context) {
return Container(
height: _headerHeight,
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
top: 10.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildButtons('', 1, 2),
),
),
Spacer(),
Divider(
height: 1.0,
color: Colors.grey,
),
],
),
);
}
Widget _buildBottomDrawerBody(BuildContext context) {
return Container(
width: double.infinity,
height: _bodyHeight,
child: SingleChildScrollView(
child: Column(
children: _buildButtons('Body', 1, 25),
),
),
);
}
List<Widget> _buildButtons(String prefix, int start, int end) {
List<Widget> buttons = [];
for (int i = start; i <= end; i++)
buttons.add(TextButton(
child: Text(
'$prefix Button $i',
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
),
),
onPressed: () {
setState(() {
_button = '$prefix Button $i';
});
},
));
return buttons;
}
String _button = 'None';
double _headerHeight = 60.0;
double _bodyHeight = 180.0;
BottomDrawerController _controller = BottomDrawerController();
}
Download Details:
Author: GP-Moon
Source Code: https://github.com/GP-Moon/bottom_drawer
1625061420
Collection of free hand-picked simple CSS grid examples. Also, it includes a bunch of front-end techniques, tips, and tricks for your future reference. Hope you will like these freebies and find them useful. Happy coding!
#layouts #css grid #grid #layouts #css #css grid layout