Skip to content

Commit

Permalink
状态恢复
Browse files Browse the repository at this point in the history
  • Loading branch information
weikaiyun committed Jun 16, 2021
1 parent d056be7 commit 80c59cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mDelegate.onViewCreated(savedInstanceState);
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
mDelegate.onSaveInstanceState(outState);
}

@Override
public void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
Expand All @@ -16,6 +17,10 @@
import com.weikaiyun.fragmentation.record.TransactionRecord;

public class SupportFragmentDelegate {
static final String S_FRAGMENTATION_FRAGMENT_VISIBLE_PROP = "s_fragmentation_fragment_visible_prop";
static final String S_FRAGMENTATION_FRAGMENT_POP_PROP = "s_fragmentation_fragment_pop_prop";
static final String S_FRAGMENTATION_FRAGMENT_START_PROP = "s_fragmentation_fragment_start_prop";

int mContainerId;

private TransactionDelegate mTransactionDelegate;
Expand All @@ -27,7 +32,7 @@ public class SupportFragmentDelegate {
protected FragmentActivity _mActivity;
private ISupportActivity mSupport;

private boolean isVisible;
private boolean isVisible = false;

boolean hasEnterAnimation = false;

Expand Down Expand Up @@ -97,6 +102,11 @@ public void onAttach(Context context) {
}

public void onCreate(@Nullable Bundle savedInstanceState) {
if(savedInstanceState != null) {
startByFragmentation = savedInstanceState.getBoolean(S_FRAGMENTATION_FRAGMENT_START_PROP, false);
isVisible = savedInstanceState.getBoolean(S_FRAGMENTATION_FRAGMENT_VISIBLE_PROP, false);
canPop = savedInstanceState.getBoolean(S_FRAGMENTATION_FRAGMENT_POP_PROP, true);
}
Bundle bundle = mFragment.getArguments();
if (bundle != null) {
mContainerId = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CONTAINER);
Expand All @@ -110,6 +120,12 @@ public void onViewCreated(@Nullable Bundle savedInstanceState) {
}
}

public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(S_FRAGMENTATION_FRAGMENT_START_PROP, startByFragmentation);
outState.putBoolean(S_FRAGMENTATION_FRAGMENT_POP_PROP, canPop);
outState.putBoolean(S_FRAGMENTATION_FRAGMENT_VISIBLE_PROP, isVisible);
}

public void setBackground(View view) {
if (view.getBackground() != null) {
return;
Expand Down

0 comments on commit 80c59cd

Please sign in to comment.