Code Monkey home page Code Monkey logo

Comments (9)

gumil avatar gumil commented on May 24, 2024 1

maybe a DefaultStateChanger for Fragments is enough?

from simple-stack.

gumil avatar gumil commented on May 24, 2024 1

So far I didn't have any problems while using this:

Navigator.configure()
                .setStateChanger(FragmentStateChanger(supportFragmentManager, R.id.fragmentContainer))
                .setShouldPersistContainerChild(false)
                .install(this, fragmentContainer, HistoryBuilder.single(Key()))

I'll give an update if something needs to be done more.

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

It might be impossible because I cannot guarantee the recreation order of fragments after process death, and internally Navigator hosts the BackstackManager in a retained fragment - this is why I'm able to do Navigator.get(context) in any view

Although I also think that once Navigator creates a view, the fragment could be added to the view as the fragment will be bound to a containerId. I don't think I have tried this.

But basically the fragments in the fragment manager are recreated in an unordered manner, so it's tricky. I listen for onCreate() of the retained fragment, and I cannot tell which fragment will be alive and who isn't.

Although, maybe you can use deferred initialization and make it reliable. Hmm...

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

I'll try it out with deferred init and see what happens.

But the tricky thing is that BackstackDelegate can also be shared through the context with the getSystemService() trick, which allows it to work similarly to navigator.

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

There is a bit more configuration required for Fragments than for View, because I'd have to provide a fragment you need to inherit from. Either to have the key in the arguments, or maybe even to bind it into the view hierarchy in view inflation in onCreateView`.

Either way, I'd have to modularize the project and have the core, the navigator support, and a fragment support component.

Not a bad idea though, if I get past the intimidation of setting up multi-project for jitpack release

from simple-stack.

gumil avatar gumil commented on May 24, 2024

Any updates on this? I might also try and work on this. I'll see what I can do

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

No I've been super-busy and this would bring 2.0 with it, so it's a bit more complicated.

You can try using Navigator with one of the fragment state changers that use add/attach/detach/remove and see if it's stable enough, in the meantime. Just use Navigator.configure().setStateChanger(new FragmentStateChanger()).shouldPersistContainerChild(false).install(...)

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

@gumil if there can be an issue with it, it's after process death.

You can verify process death behavior by putting your app in background with HOME, press "Terminate application" button in Android Studio (it's a Red X in the logcat tab), then restart your app in launcher.

If you get unpredictable behavior, like fragments being reloaded multiple times and stuff, then it doesn't work well.

But there is a chance that it does work.

from simple-stack.

Zhuinden avatar Zhuinden commented on May 24, 2024

1.) navigator CAN be used with Fragments, although it's not possible if you use ScopedServices + FragmentFactory.

Otherwise, it works fine.

In fact, now it is preferred for 2.x.

2.) this would introduce a lot of complexity for maintenance so it won't happen. 🤔

from simple-stack.

Related Issues (20)

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.