Git Product home page Git Product logo

codelab-android-navigation's Introduction

Android Navigation codelab

Content: https://codelabs.developers.google.com/codelabs/android-navigation/

License

Copyright 2018 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

codelab-android-navigation's People

Contributors

ceruleanotter avatar codingjeremy avatar ianhanniballake avatar josealcerreca avatar osuleymanova avatar tiembo 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  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

codelab-android-navigation's Issues

Navigation-Design Preview not updating

If I try to add a new fragment/actions(for ex.) in the text tab rather than adding it from the design tab; once I add it to the action tab, the changes are not reflected on the design tab. Moreover there is no refresh option that I could see to refresh the design tab.

It would be great, if the design tab could refresh real time based on the metadata added in the text tab.

Step10 DeepLinkAppWidgetProvider's code is Java

https://codelabs.developers.google.com/codelabs/android-navigation/index.html?index=..%2F..%2Fio2018#9

Step10 DeepLinkAppWidgetProvider's code is not Kotlin.

Add a Deep Link
We'll use the NavDeepLinkBuilder to hook up an app widget to a destination.

  1. Open DeepLinkAppWidgetProvider

  2. Add a PendingIntent constructed with NavDeepLinkBuilder:

DeepLinkAppWidgetProvider

Bundle args = new Bundle();
args.putString("myarg", "From Widget");
PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
    .setGraph(R.navigation.mobile_navigation)
    .setDestination(R.id.android)
    .setArguments(args)
    .createPendingIntent();

remoteViews.setOnClickPendingIntent(R.id.deep_link, pendingIntent);

I think It's needs to replace Kotlin's code

FlowStepFragmentDirections is not generating static methods for passing safe args

As per the documentation, Directions classes are generated for every distinct destination with actions.

Now consider a scenario:

Suppose, There are three fragments FragA(with no argument), FragB( with one argument), FragC(with two argument).

In the navigation graph, create two instances of Frag A , single instance of Frag B , single instance of Frag C.

From first instance of Frag A create an action named "action_next" to Frag B.
From second instance of Frag A create an action named "action_next" to FragC.

Build the project and it will generate Direction class for Frag A. Only, single "ActionNext" method is getting generated instead of two.

Since there is only one "ActionNext" method so it should behave as per the context in which it is being used; but it appears that static code of direction class is not handling it right now.

popUpTo causes crash after navigating back and trying to navigate again

I have navigation graph like this:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_nav"
    app:startDestination="@id/collectionFragment">
    <fragment
        android:id="@+id/collectionFragment"
        android:name="com.antanassepikas.navbug.CollectionFragment"
        android:label="fragment_collection"
        tools:layout="@layout/fragment_collection" >
        <action
            android:id="@+id/action_collectionFragment_to_viewFragment"
            app:destination="@id/viewFragment" />
    </fragment>
    <fragment
        android:id="@+id/viewFragment"
        android:name="com.antanassepikas.navbug.ViewFragment"
        android:label="fragment_view"
        tools:layout="@layout/fragment_view" >
        <action
            android:id="@+id/action_viewFragment_to_editFragment"
            app:destination="@id/editFragment" />
    </fragment>
    <fragment
        android:id="@+id/editFragment"
        android:name="com.antanassepikas.navbug.EditFragment"
        android:label="fragment_edit"
        tools:layout="@layout/fragment_edit" >
        <action
            android:id="@+id/action_editFragment_to_viewFragment"
            app:destination="@id/viewFragment"
            app:popUpTo="@+id/viewFragment"
            app:popUpToInclusive="true" />
    </fragment>
</navigation>

Note that the last action has

app:popUpTo="@+id/viewFragment"
app:popUpToInclusive="true" 

When navigated back from the last action this should open fragment previous to viewFragment instead of whatever the actual backstack is - And it does just that.

However event though @+id/collectionFragment after "Back Button" is opened and visible, further navigation actions cause crash.

java.lang.IllegalArgumentException: navigation destination com.antanassepikas.navbug:id/action_collectionFragment_to_viewFragment is unknown to this NavController 
at androidx.navigation.NavController.navigate(NavController.java:669) 
at androidx.navigation.NavController.navigate(NavController.java:628) 
at androidx.navigation.NavController.navigate(NavController.java:616) 
at com.antanassepikas.navbug.CollectionFragment$onCreateView$$inlined$apply$lambda$1.onClick(CollectionFragment.kt:17) at android.view.View.performClick(View.java:6891) 
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26083) 
at android.os.Handler.handleCallback(Handler.java:789) 
at android.os.Handler.dispatchMessage(Handler.java:98) 
at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6938) 
at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

I think this has to do something with destination not being changed correctly, because when printing out what destinations change during this action cycle cycle this is what I see:

0 -  com.antanassepikas.navbug:id/collectionFragment // when collection fragment is opened by default
1 -  com.antanassepikas.navbug:id/viewFragment // when navigating from collection to item
2 -  com.antanassepikas.navbug:id/editFragment // when navigating from item view to item edit
3 -  com.antanassepikas.navbug:id/viewFragment // when navigating from item edit to item view
4 -  com.antanassepikas.navbug:id/collectionFragment // this destinations happens automatically
5 -  com.antanassepikas.navbug:id/viewFragment // this destinations happens automatically

At this point viewFragment is open and when "Back Button" is clicked collectionFragment is opened which is what is to be expected, but now when trying to opening another item a crash happens.

I created sample project where this is reproducible https://github.com/sepikas/navigation-bug

Step 8, missing information

Under Using NavigationUI, there's only two steps showing how to update the drawer and bottom navigation along with verifying that these menu items are shown when running the app. But, the actual implementation of the navigation from these items are missing.

Unresolved Reference: R

After checking out the project, the code compiles and builds - but receive Unresolved Reference: R for all files that use it.

Tried the following:

  1. clean, build
  2. sync gradle
  3. invalidate cache and restart
  4. checked xml files and added to ensure resource files have and xmlns:android="http://schemas.android.com/apk/res/android"
    5. update gradle to stable version: com.android.tools.build:gradle:3.2.1 (this worked)

resources:
https://stackoverflow.com/questions/17421104/android-studio-marks-r-in-red-with-error-message-cannot-resolve-symbol-r-but
https://stackoverflow.com/questions/51621301/android-studio-3-1-3-unresolved-reference-r-kotlin

element `nav-graph` not allowed here

My editor complains that element nav-graph is not allowed here for this line of code
https://github.com/googlecodelabs/android-navigation/blob/master/app/src/main/AndroidManifest.xml#L42
and after following the steps suggested in the codelabs tutorial here https://codelabs.developers.google.com/codelabs/android-navigation/#10, in the very last step - this doesn't happen

Opening www.example.com/hello/ triggers the intent chooser

I just see a search result on google.com. In my case I launched it in a Genymotion VM which only had one browser -- which I assume would mean there was nothing to resolve for the intent chooser (which in the example shows Chrome and WebView Browser Tester)

Does the nav-graph element need to go somewhere else?

Editor
Android Studio 3.3 Canary 10
Build #AI-182.4129.33.33.4996246, built on September 6, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Player VM
Nexus 6X API 23

Loopin on change orientation

When changing orientation with open fragment. The application loops. The same fragment is started and restarted eternally.

Issue with using Kotlin extensions plugin

Is there any specific reason why this works:

view.findViewById<Button>(R.id.navigate_dest_bt)?.setOnClickListener( Navigation.createNavigateOnClickListener(R.id.flow_step_one, null) )

But this does not:

navigate_dest_bt.setOnClickListener { Navigation.createNavigateOnClickListener(R.id.flow_step_one, null) }

Up navigation in deep link tab

When in portrait mode (so the navigation drawer is not visible, but the bottom bar is) the up button in the toolbar is shown when switching to the deep link tab via the bottom bar. As far as I know this shouldn't be the case. I would only have it visible when you're in landscape mode and the drawer is active.

I understand that this is done by the Navigation Components handling switching the tab as a simple forward navigation. However that isn't the case - as all tabs are created equal. ;)

So might be that's not a bug in the codelab, but in the Navigation Components library? Then again, it would also have to accomodate for what happens when you then switch to landscape where the up button would suddenly become appropriate - this doesn't sound trivial.

Step 10. Deep Linking - does not open android fragment

Clicking on the deep link widget on the homescreen does not open up the android fragment - it doesn't seem to do anything.

I have uncommented the code referred to in this step in the DeepLinkAppWidgetProvider.kt file within the TODO comments (which is incorrectly labelled as Step 11 in the code) - see below - but perhaps there is a step missing?

    val args = Bundle()
    args.putString("myarg", "From Widget")
    // TODO Step 11 - construct and set a PendingIntent using DeepLinkBuilder
    val pendingIntent = NavDeepLinkBuilder(context)
        .setGraph(R.navigation.mobile_navigation)
        .setDestination(R.id.android)
        .setArguments(args)
        .createPendingIntent()

    remoteViews.setOnClickPendingIntent(R.id.deep_link, pendingIntent)
    // TODO ENDSTEP 11

minor issues in step 8 of the codelab

For step 8 as of master 2bbc0ac:

  1. the link to safe args goes to the overview of the documentation not the safe args section
    1.1. current link: https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#Safe-args
    1.2. correct link: https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#Safe-args

  2. step 8 does not include the safe calls for arguments in the repository's code as the screenshot does, neither does the code below the screenshot.

  3. the codelab does not include the ktx option as instructed by the documentation:
    3.1. "In your receiving destination’s code, use the getArguments() method to retrieve the bundle and use its contents. When using the -ktx dependencies, Kotlin users can also use the by navArgs() property delegate to access arguments."

  4. This one is not about the codelab, but the documentation itself. It suggests doing this:

val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
   v.findNavController().navigate(action)

but as far as I understood it is not possible to pass the argument value directly into the action.
It should do as the codelab instructs and add the value into the argument from the action:

    val action = HomeFragmentDirections.nextAction()
    action.setFlowStepNumber(1)
    findNavController().navigate(action)

Step 5, createNavClickListener in clickListener

at the bottom of the page

val button = view.findViewById<Button>(R.id.navigate_destination_button)
button?.setOnClickListener(
        Navigation.createNavigateOnClickListener(R.id.flow_step_one_dest, null)
)

calling createNavigateOnClickListener in onClickListener isn't equal to previous example with

val button = view.findViewById<Button>(R.id.navigate_destination_button)
button?.setOnClickListener(
        findNavController().navigate(R.id.flow_step_one_dest)
)

should be like

Navigation.createNavigateOnClickListener(R.id.flow_step_one_dest, null)

another point is that setOnClickListener should be with curly braces { }

createNavigateOnClickListener

Hi,

I'm not sure if I'm missing something but when I create a navigate click listener using a destination instead of an action, the intent doesn't work.

Using Navigation.findNavController(view).navigate(destinationId) works well.

Thanks

Step 11: "Search bar" is vague

It might be clearer if the instructions just said "Go to the Google app and enter 'www.example.com/blah'. If you followed the instructions, you'll see a disambiguation dialog". I don't use the Google app so I was puzzled where to test out the code for step 11. It took me a while to figure out where the search bar is

can't run project

why the project is built upon android studio 3.2 preview version
it would be better if build with normal android studio so anyone can use it

I am getting these errors when trying to build the project
Failed to resolve: appcompat-v7
Open File

Failed to resolve: cardview-v7
Open File

Failed to resolve: animated-vector-drawable
Open File

Failed to resolve: support-vector-drawable
Open File

Failed to resolve: support-v4
Open File

Failed to resolve: support-fragment
Open File

Failed to resolve: support-core-ui
Open File

Failed to resolve: runtime
Open File

Failed to resolve: livedata-core
Open File

Failed to resolve: common
Open File

Failed to resolve: support-annotations
Open File

Failed to resolve: viewmodel
Open File

Keep data of home tab.

Dear Developers,
I have a problem which related keeping data.
When user click home tab again fragment is re-created again and data is loaded again.
I'd like to keep data previously same Youtube app.
Could you have any solution for this problem with Navigation?
Thank you very much for your tuts.

Step 11. Deep link in code sample is incorrect.

Sample code shown is:

<deepLink app:uri="www.example.com/{myarg}"/>

That's the deep link from the previous step. In this step, it should be:

<deepLink app:uri="www.iana.org/domains/{myarg}"/>

Instructions should then be to navigate to www.example.com and click the link. Upon choosing the app from the sharing list, you then see 'reserved' displayed in the fragment.

Hamburger icon doesn't open navigation drawer

After forcing the default navigation_activity.xml to be loaded on app launch (i.e.
use nav drawer), it is observed that while the nav drawer may be opened by swiping
in from the left screen edge, the hamburger icon is completely inoperable i.e. it
does nothing when pressed -- correct behavior would be to open the nav drawer.

Please add the bundle on BottomNavigationView method (setupWithNavController) (Code In Description)

I don't understand the reason why the NavigationUI doesn't admit a override on the onNavDestinationSelected or just a main bundle for all the view Like this:

setupWithNavController(mBinding.navigation, mNavController, mArguments.toBundle())
onNavDestinationSelected(item, navController, false, args)

And all fragments that are implemented in the BottomNavigationView can have those arguments.

I had to use all the legacy code of NavigationUI just to change this section from null to my Bundle arguments:

fun onNavDestinationSelected(... , bundle: Bundle? = null){
...
navController.navigate(item.itemId, bundle, options)
}

Androidx migration

This code lab uses old api libraries, which doesn't include for instance app:argType change on navigation.

It should be migrated to androidx to keep up with latest framework changes

Why Recreate Fragment when bottomNavigationView.onNavigationItemSelected ?

I click on bottomNavigationView From DeeplinkFragment to HomeFragment, Discovery will recreate HomeFragment.

Why ? It is a feature or bug ?

2019-01-31 18:08:31.500 29778-29778/com.example.android.codelabs.navigation D/Test: onCreate
2019-01-31 18:08:34.453 29778-29778/com.example.android.codelabs.navigation D/Test: onCreate

Please create branch containing final project state

Excellent codelab, essentially "living documentation" for the AAC "Navigation" component.

One way to make it even more useful would be to create a branch containing the final
state of the project (reflecting state when the codelab is completed)

Navigation Drawer / icon in portrait mode ?

as stated on another ticket here: "...You also just will see the drawer when e.g. entering split screen mode or rotate to landscape."

can you please clarify how we can show the drawer menu when in portrait mode ? i think it would be great if this can be added to the tutorial (which is fantastic).

Remove Settings overflow in Toolbar from Settings Fragment?

The app structure used in the codelab implements the toolbar as fixed chrome (outside the fragment in navigation_activity.xml) but shows how flexible it can still be depending on the context - the title/label and menu items and options can change with each fragment destination.

However I noticed when you navigate to the settings fragment that the settings overflow is still shown in the toolbar. It probably doesn't make sense to have it there though as the user is already in settings?

How would you remove the settings overflow in this case?

Step 6 error in the TODO code

when adding the navigation options the code in the TODO is this:

val options = NavOptions.Builder()
    .setEnterAnim(R.anim.slide_in_right)
    .setExitAnim(R.anim.slide_out_left)
    .setPopEnterAnim(R.anim.slide_in_left)
    .setPopExitAnim(R.anim.slide_out_right)
    .build()

view.findViewById<Button>(R.id.navigate_dest_bt)?.setOnClickListener {
    findNavController(it).navigate(R.id.flow_step_one, null, options)
}

This is not compiling because it is the findNavController is expecting a fragment but is getting a 'View' as an input
it should be the keyword 'this' to pass the current fragment and the transition

Step 10 Deep Linking - Up button not showing

Step 10 "Deep Linking to a destination" contains the following screen shot at the end of the page. Notice the Up button on the upper-left corner.

image

I can't speak for others, but the Up button never showed up for my case, even when I reach the screen from the widget in the home screen. The only way to make it show is to remove R.id.deeplink_dest in MainActivity.kt.

class MainActivity : AppCompatActivity() {
    ...
    // TODO STEP 9.5 - Create an AppBarConfiguration with the correct top-level destinations
    // You should also remove the old appBarConfiguration setup above
    val drawerLayout : DrawerLayout? = findViewById(R.id.drawer_layout)
    appBarConfiguration = AppBarConfiguration(
            setOf(R.id.home_dest, R.id.deeplink_dest),    // <-- Remove "R.id.deeplink_dest".
            drawerLayout)

But if I do, the Up button always shows up in "Deep Link" screen, even when I reach the screen from Navigation Drawer or Bottom Navigation.

Is the Up button supposed to show up only when I reach it from the "Deep Link" widget? If so, how do I make it show up, but not show up when reaching it from Navigation Drawer or Bottom Navigation?

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.