question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animate and Screen rotation 2

See original GitHub issue

Здравствуйте!

Продолжение вот этого вопроса: #37 Есть одно активити и 3 дополнительных слоя, которые вызываем так:

Activity:

public class StartActivity extends MvpAppCompatActivity implements StartActivityView {
    @InjectPresenter
    StartActivityPresenter pStartActivityPresenter;

    @BindView(R.id.rootContainer) ViewGroup rootContainer;

    Scene scene_setusergendername;
    Scene scene_selectchild;
    Scene scene_setchildname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        ButterKnife.bind(this);

        scene_setusergendername = Scene.getSceneForLayout(rootContainer, R.layout.scene_setusergendername, this);
        scene_selectchild = Scene.getSceneForLayout(rootContainer, R.layout.scene_selectchild, this);
        scene_setchildname = Scene.getSceneForLayout(rootContainer, R.layout.scene_setchildname, this);
    }

    public void goSetUserGenderName(View view) {
        pStartActivityPresenter.changeScene("SetUserGenderName");
    }

    public void goSelectChild(View view) {
        pStartActivityPresenter.changeScene("SelectChild");
    }

    public void goSetChildName(View view) {
        pStartActivityPresenter.changeScene("SetChildName");
    }

    @Override
    public void showScene_SetUserGenderName() {
        TransitionManager.go(scene_setusergendername, TransitionInflater.from(StartActivity.this).inflateTransition(R.transition.fade_out_in));
    }

    @Override
    public void showScene_SelectChild() {
        TransitionManager.go(scene_selectchild, TransitionInflater.from(StartActivity.this).inflateTransition(R.transition.fade_out_in));
    }

    @Override
    public void showScene_SetChildName() {
        TransitionManager.go(scene_setchildname, TransitionInflater.from(StartActivity.this).inflateTransition(R.transition.fade_out_in));
    }
}

Presenter:

@InjectViewState
public class StartActivityPresenter extends MvpPresenter<StartActivityView> {
    public StartActivityPresenter() {    }

    public void changeScene(String scenename) {
        if ("SetUserGenderName".equals(scenename)) {
            getViewState().showScene_SetUserGenderName();
        }
        else if ("SelectChild".equals(scenename)) {
            getViewState().showScene_SelectChild();
        }
        else if ("SetChildName".equals(scenename)) {
            getViewState().showScene_SetChildName();
        }
    }
}

View:

public interface StartActivityView extends MvpView {
    void showScene_SetUserGenderName();
    void showScene_SelectChild();
    void showScene_SetChildName();
}

При нажатии кнопок на слоях, переходы обрабатываются нормально, претензий нет. Как только произошел поворот устройства, то срабатывает событие goSetUserGenderName. Т.е. после старта приложения нажали кнопку 1 раз - перешли на второй экран, нажали на кнопку снова - перешли на третий, еще раз - на четвертый экран. Повернули устройство - автоматом перешли на второй. Как сохранить состояние экрана в этом случае? isInRestoreState(this) не спасает.

Спасибо!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:26

github_iconTop GitHub Comments

2reactions
sennecocommented, Nov 11, 2016

Ага. ViewState хранится внутри Presenter. Каждая команда, которая попадает во ViewState, сохраняется внутри ViewState. Когда к Presenter аттачится View, ViewState отправляет в неё хранящиеся команды.

0reactions
crysancommented, Nov 15, 2016

Убил себе мозг. Моху сохраняет состояние переменной. Проверено! Было так:

    @Override
    public void showScene_SelectChild() {
        TransitionManager.go(scene_selectchild, TransitionInflater.from(StartActivity.this).inflateTransition(R.transition.fade_out_in));
    }

Стало:

    @Override
    public void showScene_SelectChild() {
        if (pStartActivityPresenter.isInRestoreState(this)) {
            rootContainer.removeAllViews();
            rootContainer.addView(scene_selectchild_);
            return;
        }
        TransitionManager.go(scene_selectchild, TransitionInflater.from(StartActivity.this).inflateTransition(R.transition.fade_out_in));
    }

В чем проблема отработки анимации после поворота, так и не понял (( Но теперь все работает.

Спасибо!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I reset the stage rotation?! - Adobe Support Community
Press Ctrl + 0 (Win) or Cmd + 0 (Mac). Likes.
Read more >
[iOS 16 Pub beta 2] Screen rotation animation delay issue.
When rotating the screen, there is a delay in the animation around the corners. (Not just youtube)
Read more >
Taking Control of Rotation Animations in iOS - BiTE Interactive
-CGFloat.pi / 2 : Animates a counterclockwise rotation of 90 degrees. CGFloat.pi * 99 / 100 : Animates a clockwise rotation ...
Read more >
ios - Animate changes during device rotation based on size ...
2 Answers 2 ... As Joey points out, one can use viewWillTransitionToSize to be notified of the new size, and then use animateAlongsideTransition...
Read more >
21.5.2 Rotation Animation
21.5.2 Rotation Animation. The system calculates where to display the object based on the specified word address, [Source Range], and [Angle Range].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found