react-native-navigation的迁移库

Modal.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.reactnativenavigation.controllers;
  2. import android.app.Dialog;
  3. import android.content.DialogInterface;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.view.Window;
  6. import android.view.WindowManager;
  7. import com.facebook.react.bridge.Callback;
  8. import com.reactnativenavigation.R;
  9. import com.reactnativenavigation.layouts.Layout;
  10. import com.reactnativenavigation.layouts.ModalScreenLayout;
  11. import com.reactnativenavigation.layouts.ScreenStackContainer;
  12. import com.reactnativenavigation.params.ContextualMenuParams;
  13. import com.reactnativenavigation.params.ScreenParams;
  14. import com.reactnativenavigation.params.TitleBarButtonParams;
  15. import com.reactnativenavigation.params.TitleBarLeftButtonParams;
  16. import java.util.List;
  17. public class Modal extends Dialog implements DialogInterface.OnDismissListener, ScreenStackContainer {
  18. private final AppCompatActivity activity;
  19. private final OnModalDismissedListener onModalDismissedListener;
  20. private final ScreenParams screenParams;
  21. private Layout layout;
  22. public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
  23. layout.setTopBarVisible(screenInstanceId, hidden, animated);
  24. }
  25. void setTitleBarTitle(String screenInstanceId, String title) {
  26. layout.setTitleBarTitle(screenInstanceId, title);
  27. }
  28. void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
  29. layout.setTitleBarSubtitle(screenInstanceId, subtitle);
  30. }
  31. void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
  32. layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
  33. }
  34. public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButton) {
  35. layout.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButton);
  36. }
  37. public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
  38. layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
  39. }
  40. public void dismissContextualMenu(String screenInstanceId) {
  41. layout.dismissContextualMenu(screenInstanceId);
  42. }
  43. @Override
  44. public boolean onTitleBarBackButtonClick() {
  45. if (!layout.onBackPressed()) {
  46. onBackPressed();
  47. }
  48. return true;
  49. }
  50. public void onSideMenuButtonClick() {
  51. }
  52. interface OnModalDismissedListener {
  53. void onModalDismissed(Modal modal);
  54. }
  55. public Modal(AppCompatActivity activity, OnModalDismissedListener onModalDismissedListener, ScreenParams screenParams) {
  56. super(activity, R.style.Modal);
  57. this.activity = activity;
  58. this.onModalDismissedListener = onModalDismissedListener;
  59. this.screenParams = screenParams;
  60. createContent();
  61. }
  62. public AppCompatActivity getActivity() {
  63. return activity;
  64. }
  65. private void createContent() {
  66. setCancelable(true);
  67. setOnDismissListener(this);
  68. requestWindowFeature(Window.FEATURE_NO_TITLE);
  69. layout = new ModalScreenLayout(getActivity(), screenParams, this);
  70. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
  71. setContentView(layout.asView());
  72. }
  73. @Override
  74. public void push(ScreenParams params) {
  75. layout.push(params);
  76. }
  77. @Override
  78. public void pop(ScreenParams screenParams) {
  79. layout.pop(screenParams);
  80. }
  81. @Override
  82. public void popToRoot(ScreenParams params) {
  83. layout.popToRoot(params);
  84. }
  85. @Override
  86. public void newStack(ScreenParams params) {
  87. layout.newStack(params);
  88. }
  89. public boolean containsNavigator(String navigatorId) {
  90. return layout.containsNavigator(navigatorId);
  91. }
  92. @Override
  93. public void destroy() {
  94. layout.destroy();
  95. }
  96. @Override
  97. public void onBackPressed() {
  98. if (!layout.onBackPressed()) {
  99. super.onBackPressed();
  100. }
  101. }
  102. @Override
  103. public void onDismiss(DialogInterface dialog) {
  104. destroy();
  105. onModalDismissedListener.onModalDismissed(this);
  106. }
  107. void onModalDismissed() {
  108. layout.onModalDismissed();
  109. }
  110. }