Navigation Menu

Skip to content

Commit

Permalink
Add simple nested screen for showing another problem with BottomNavig…
Browse files Browse the repository at this point in the history
…ationView
  • Loading branch information
PStrelchenko committed Aug 15, 2020
1 parent fa3a80b commit 7d54b32
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.aaglobal.jnc_playground.R
import kotlinx.android.synthetic.main.fragment_dashboard.*

Expand All @@ -25,6 +26,12 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
fragment_dashboard__text__counter.text = "$it"
})
fragment_dashboard__text__counter.setOnClickListener { dashboardViewModel.incCounter() }

// ========= Problem 2 =========
// When we change screen state and tap on bottom navigation tab - state of the screen will be reset!
fragment_dashboard__button__move.setOnClickListener {
findNavController().navigate(R.id.action__DashboardFragment_to_GraphicFragment)
}
}

}
@@ -0,0 +1,6 @@
package com.aaglobal.jnc_playground.ui.graphic

import androidx.fragment.app.Fragment
import com.aaglobal.jnc_playground.R

class GraphicFragment : Fragment(R.layout.fragment_graphic)
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_dashboard.xml
Expand Up @@ -32,4 +32,14 @@
app:layout_constraintTop_toBottomOf="@id/fragment_dashboard__text__title"
tools:text="100" />

<Button
android:id="@+id/fragment_dashboard__button__move"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp20"
android:text="@string/fragment_dashboard__open_graphic_screen"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fragment_dashboard__text__counter" />

</androidx.constraintlayout.widget.ConstraintLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/fragment_graphic.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
style="@style/LargeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fragment_graphic__title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 14 additions & 1 deletion app/src/main/res/navigation/mobile_navigation.xml
Expand Up @@ -15,11 +15,24 @@
android:id="@+id/navigation_dashboard"
android:name="com.aaglobal.jnc_playground.ui.dashboard.DashboardFragment"
android:label="@string/title_dashboard"
tools:layout="@layout/fragment_dashboard" />
tools:layout="@layout/fragment_dashboard">

<action
android:id="@+id/action__DashboardFragment_to_GraphicFragment"
app:destination="@id/GraphicFragment" />

</fragment>

<fragment
android:id="@+id/navigation_notifications"
android:name="com.aaglobal.jnc_playground.ui.notifications.NotificationsFragment"
android:label="@string/title_notifications"
tools:layout="@layout/fragment_notifications" />

<fragment
android:id="@+id/GraphicFragment"
android:name="com.aaglobal.jnc_playground.ui.graphic.GraphicFragment"
android:label="Graphic"
tools:layout="@layout/fragment_graphic" />

</navigation>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -3,4 +3,6 @@
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string name="fragment_graphic__title">Graphic screen title</string>
<string name="fragment_dashboard__open_graphic_screen">Open graphic screen</string>
</resources>

0 comments on commit 7d54b32

Please sign in to comment.