Browse Source

ContentView

Guy Carmeli 8 years ago
parent
commit
5f02e61af2

+ 13
- 9
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java View File

8
 import com.facebook.react.ReactRootView;
8
 import com.facebook.react.ReactRootView;
9
 import com.reactnativenavigation.react.ReactViewHacks;
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
         super(context);
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
     public void removeFromParentWithoutUnmount() {
31
     public void removeFromParentWithoutUnmount() {
33
         ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
38
         ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
34
         ((ViewGroup) getParent()).removeView(this);
39
         ((ViewGroup) getParent()).removeView(this);
35
     }
40
     }
36
-
37
 }
41
 }

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/views/ScrollDirectionListener.java View File

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

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/ScrollViewAttacher.java View File

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