react-native-navigation的迁移库

ScreenLayout.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.reactnativenavigation.layouts;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import android.widget.LinearLayout;
  5. import com.facebook.react.ReactInstanceManager;
  6. import com.reactnativenavigation.views.TitleBarButton;
  7. import com.reactnativenavigation.views.ContentView;
  8. import com.reactnativenavigation.views.ScrollDirectionListener;
  9. import com.reactnativenavigation.views.TitleBar;
  10. import java.util.List;
  11. import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
  12. import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
  13. public class ScreenLayout extends LinearLayout implements ScrollDirectionListener.OnScrollChanged {
  14. public static class Params {
  15. String moduleName;
  16. Bundle passProps;
  17. List<TitleBarButton> buttons;
  18. }
  19. private final ReactInstanceManager reactInstanceManager;
  20. private final String moduleName;
  21. private final Bundle passProps;
  22. private final List<TitleBarButton> buttons;
  23. private ContentView contentView;
  24. private TopBar topBar;
  25. public ScreenLayout(Context context, ReactInstanceManager reactInstanceManager, Params screenParams) {
  26. super(context);
  27. this.reactInstanceManager = reactInstanceManager;
  28. moduleName = screenParams.moduleName;
  29. passProps = screenParams.passProps;
  30. buttons = screenParams.buttons;
  31. setOrientation(VERTICAL);
  32. createViews();
  33. }
  34. private void createViews() {
  35. addTopBar();
  36. addTitleBarAndSetButtons();
  37. addContentView();
  38. }
  39. private void addTitleBarAndSetButtons() {
  40. TitleBar titleBar = new TitleBar(getContext());
  41. titleBar.setButtons(buttons);
  42. topBar.addView(titleBar);
  43. }
  44. private void addTopBar() {
  45. topBar = new TopBar(getContext());
  46. addView(topBar, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
  47. }
  48. private void addContentView() {
  49. contentView = new ContentView(getContext(), reactInstanceManager, moduleName, passProps, this);
  50. addView(contentView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
  51. }
  52. @Override
  53. public void onScrollChanged(ScrollDirectionListener.Direction direction) {
  54. }
  55. }