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;
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
add a comment |
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
add a comment |
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
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
android mvvm fragment android-architecture-components android-livedata
asked Mar 25 at 3:23
lost17lost17
4572826
4572826
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think, you need:
- manually restore view state (according current state in
LiveData
) when fragment recreated - 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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
I think, you need:
- manually restore view state (according current state in
LiveData
) when fragment recreated - 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.
add a comment |
I think, you need:
- manually restore view state (according current state in
LiveData
) when fragment recreated - 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.
add a comment |
I think, you need:
- manually restore view state (according current state in
LiveData
) when fragment recreated - 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.
I think, you need:
- manually restore view state (according current state in
LiveData
) when fragment recreated - 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.
answered Mar 25 at 6:27
XIII-thXIII-th
3,37221840
3,37221840
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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