Guy Carmeli vor 8 Jahren
Ursprung
Commit
5f02e61af2

+ 13
- 9
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Datei anzeigen

@@ -8,19 +8,24 @@ import com.facebook.react.ReactInstanceManager;
8 8
 import com.facebook.react.ReactRootView;
9 9
 import com.reactnativenavigation.react.ReactViewHacks;
10 10
 
11
-public class ContentView extends ReactRootView implements ScrollDirectionListener.OnChanged {
11
+public class ContentView extends ReactRootView {
12 12
 
13
-    private final ScrollViewAttacher scrollViewAttacher;
13
+    private final ReactInstanceManager reactInstanceManager;
14
+    private final String moduleName;
15
+    private final Bundle passProps;
16
+    private final ScrollDirectionListener.OnScrollChanged scrollListener;
14 17
 
15
-    public ContentView(Context context, ReactInstanceManager reactInstanceManager, String moduleName, Bundle passProps) {
18
+    public ContentView(Context context, ReactInstanceManager reactInstanceManager, String moduleName, Bundle passProps, ScrollDirectionListener.OnScrollChanged scrollListener) {
16 19
         super(context);
17
-        startReactApplication(reactInstanceManager, moduleName, passProps);
18
-        scrollViewAttacher = new ScrollViewAttacher(this, this);
20
+        this.reactInstanceManager = reactInstanceManager;
21
+        this.moduleName = moduleName;
22
+        this.passProps = passProps;
23
+        this.scrollListener = scrollListener;
19 24
     }
20 25
 
21
-    @Override
22
-    public void onScrollChanged(ScrollDirectionListener.Direction direction) {
23
-
26
+    public void init() {
27
+        startReactApplication(reactInstanceManager, moduleName, passProps);
28
+        new ScrollViewAttacher(this, scrollListener).attach();
24 29
     }
25 30
 
26 31
     public void removeFromParentWithoutUnmount() {
@@ -33,5 +38,4 @@ public class ContentView extends ReactRootView implements ScrollDirectionListene
33 38
         ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
34 39
         ((ViewGroup) getParent()).removeView(this);
35 40
     }
36
-
37 41
 }

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/views/ScrollDirectionListener.java Datei anzeigen

@@ -8,15 +8,15 @@ public class ScrollDirectionListener implements ViewTreeObserver.OnScrollChanged
8 8
         Up, Down
9 9
     }
10 10
 
11
-    public interface OnChanged {
11
+    public interface OnScrollChanged {
12 12
         void onScrollChanged(Direction direction);
13 13
     }
14 14
 
15 15
     private final ViewGroup view;
16
-    private OnChanged onChanged;
16
+    private OnScrollChanged onChanged;
17 17
     private int lastScrollY = -1;
18 18
 
19
-    public ScrollDirectionListener(ViewGroup view, OnChanged onChanged) {
19
+    public ScrollDirectionListener(ViewGroup view, OnScrollChanged onChanged) {
20 20
         this.view = view;
21 21
         this.onChanged = onChanged;
22 22
     }

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/ScrollViewAttacher.java Datei anzeigen

@@ -9,11 +9,11 @@ import com.reactnativenavigation.utils.ViewUtils;
9 9
 public class ScrollViewAttacher implements View.OnAttachStateChangeListener {
10 10
 
11 11
     private final ContentView view;
12
-    private final ScrollDirectionListener.OnChanged onChanged;
12
+    private final ScrollDirectionListener.OnScrollChanged onChanged;
13 13
     private ScrollView scrollView;
14 14
     private ScrollDirectionListener scrollDirectionListener;
15 15
 
16
-    public ScrollViewAttacher(ContentView view, ScrollDirectionListener.OnChanged onChanged) {
16
+    public ScrollViewAttacher(ContentView view, ScrollDirectionListener.OnScrollChanged onChanged) {
17 17
         this.view = view;
18 18
         this.onChanged = onChanged;
19 19
     }