MVVM shared state with animated viewsHow to save an Android Activity state using save instance state?What is the difference between MVC and MVVM?Override back button to act like home buttonPrevent ViewPager from destroying off-screen viewsWhat is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?Dilemma: when to use Fragments vs Activities:MVVM notify View about loading stateShared element transition - animate only the visible part of the shared viewAdding Animation to State Changes with LiveDataObserving LiveData instance from View

2 Managed Packages in 1 Dev Org

New Site Design!

What do I put on my resume to make the company i'm applying to think i'm mature enough to handle a job?

I have found ports on my Samsung smart tv running a display service. What can I do with it?

Is it common to delay the start date of a postdoc?

Why is gun control associated with the socially liberal Democratic party?

How useful is the GRE Exam?

My husband's visa refused but mine wasn't -- can I travel?

How "fast" does astronomical events happen?

Numerical second order differentiation

Print the phrase "And she said, 'But that's his.'" using only the alphabet

How to know whether to write accidentals as sharps or flats?

How do credit card companies know what type of business I'm paying for?

How to make a villain when your PCs are villains?

Time at 1G acceleration to travel 100000 light years

How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?

High-end PC graphics circa 1990?

How did Avada Kedavra get its name?

How can the US president give an order to a civilian?

Can "Es tut mir leid" be used to express empathy rather than remorse?

100-doors puzzle

What are the mechanical differences between Adapt and Monstrosity?

Fill the maze with a wall-following Snake until it gets stuck

How can I maintain game balance while allowing my player to craft genuinely useful items?



MVVM shared state with animated views


How to save an Android Activity state using save instance state?What is the difference between MVC and MVVM?Override back button to act like home buttonPrevent ViewPager from destroying off-screen viewsWhat is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?Dilemma: when to use Fragments vs Activities:MVVM notify View about loading stateShared element transition - animate only the visible part of the shared viewAdding Animation to State Changes with LiveDataObserving LiveData instance from View






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Assuming I have 2 fragments A and B. Each of them contains a view respectively viewA and viewB. Both views are hidden by default.



There is a shared view model called sharedVM (linked to the activity)



An event A from the user will show viewA with animation and hide viewB with animation (if viewB is visible)
An event B from the user will show viewB with animation and hide viewA with animation (if viewA is visible)



I though about:



Solution 1:
Use a LiveData state inside sharedVM to know if views are hidden or visible.
But then when the fragment is destroyed and recreated:
The hide/show animation will play again, that's not good.



Solution 2:
Use LiveDataEvent inside sharedVM to know dispatch and trigger the animations.
But then when the fragment is destroyed and recreated:
I have no idea about the previous states of the views...



What would be a better approach?










share|improve this question




























    0















    Assuming I have 2 fragments A and B. Each of them contains a view respectively viewA and viewB. Both views are hidden by default.



    There is a shared view model called sharedVM (linked to the activity)



    An event A from the user will show viewA with animation and hide viewB with animation (if viewB is visible)
    An event B from the user will show viewB with animation and hide viewA with animation (if viewA is visible)



    I though about:



    Solution 1:
    Use a LiveData state inside sharedVM to know if views are hidden or visible.
    But then when the fragment is destroyed and recreated:
    The hide/show animation will play again, that's not good.



    Solution 2:
    Use LiveDataEvent inside sharedVM to know dispatch and trigger the animations.
    But then when the fragment is destroyed and recreated:
    I have no idea about the previous states of the views...



    What would be a better approach?










    share|improve this question
























      0












      0








      0








      Assuming I have 2 fragments A and B. Each of them contains a view respectively viewA and viewB. Both views are hidden by default.



      There is a shared view model called sharedVM (linked to the activity)



      An event A from the user will show viewA with animation and hide viewB with animation (if viewB is visible)
      An event B from the user will show viewB with animation and hide viewA with animation (if viewA is visible)



      I though about:



      Solution 1:
      Use a LiveData state inside sharedVM to know if views are hidden or visible.
      But then when the fragment is destroyed and recreated:
      The hide/show animation will play again, that's not good.



      Solution 2:
      Use LiveDataEvent inside sharedVM to know dispatch and trigger the animations.
      But then when the fragment is destroyed and recreated:
      I have no idea about the previous states of the views...



      What would be a better approach?










      share|improve this question














      Assuming I have 2 fragments A and B. Each of them contains a view respectively viewA and viewB. Both views are hidden by default.



      There is a shared view model called sharedVM (linked to the activity)



      An event A from the user will show viewA with animation and hide viewB with animation (if viewB is visible)
      An event B from the user will show viewB with animation and hide viewA with animation (if viewA is visible)



      I though about:



      Solution 1:
      Use a LiveData state inside sharedVM to know if views are hidden or visible.
      But then when the fragment is destroyed and recreated:
      The hide/show animation will play again, that's not good.



      Solution 2:
      Use LiveDataEvent inside sharedVM to know dispatch and trigger the animations.
      But then when the fragment is destroyed and recreated:
      I have no idea about the previous states of the views...



      What would be a better approach?







      android mvvm fragment android-architecture-components android-livedata






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 3:23









      lost17lost17

      4572826




      4572826






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think, you need:



          1. manually restore view state (according current state in LiveData) when fragment recreated

          2. make view state observer ignore change if view currently in this state

          You can do it in onViewCreated() callback. This fix make your first solution works.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330887%2fmvvm-shared-state-with-animated-views%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I think, you need:



            1. manually restore view state (according current state in LiveData) when fragment recreated

            2. make view state observer ignore change if view currently in this state

            You can do it in onViewCreated() callback. This fix make your first solution works.






            share|improve this answer



























              0














              I think, you need:



              1. manually restore view state (according current state in LiveData) when fragment recreated

              2. make view state observer ignore change if view currently in this state

              You can do it in onViewCreated() callback. This fix make your first solution works.






              share|improve this answer

























                0












                0








                0







                I think, you need:



                1. manually restore view state (according current state in LiveData) when fragment recreated

                2. make view state observer ignore change if view currently in this state

                You can do it in onViewCreated() callback. This fix make your first solution works.






                share|improve this answer













                I think, you need:



                1. manually restore view state (according current state in LiveData) when fragment recreated

                2. make view state observer ignore change if view currently in this state

                You can do it in onViewCreated() callback. This fix make your first solution works.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 6:27









                XIII-thXIII-th

                3,37221840




                3,37221840





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330887%2fmvvm-shared-state-with-animated-views%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현