-
-
Notifications
You must be signed in to change notification settings - Fork 498
/
Screen.java
112 lines (92 loc) · 3 KB
/
Screen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.swmansion.rnscreens;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.uimanager.PointerEvents;
import com.facebook.react.uimanager.ReactPointerEventsView;
public class Screen extends ViewGroup implements ReactPointerEventsView {
public static class ScreenFragment extends Fragment {
private Screen mScreenView;
public ScreenFragment() {
throw new IllegalStateException("Screen fragments should never be restored");
}
@SuppressLint("ValidFragment")
public ScreenFragment(Screen screenView) {
super();
mScreenView = screenView;
}
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return mScreenView;
}
}
private final Fragment mFragment;
private @Nullable ScreenContainer mContainer;
private boolean mActive;
private boolean mTransitioning;
public Screen(Context context) {
super(context);
mFragment = new ScreenFragment(this);
}
@Override
protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
// no-op
}
/**
* While transitioning this property allows to optimize rendering behavior on Android and provide
* a correct blending options for the animated screen. It is turned on automatically by the container
* when transitioning is detected and turned off immediately after
*/
public void setTransitioning(boolean transitioning) {
if (mTransitioning == transitioning) {
return;
}
mTransitioning = transitioning;
super.setLayerType(transitioning ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
}
@Override
public boolean hasOverlappingRendering() {
return mTransitioning;
}
@Override
public PointerEvents getPointerEvents() {
return mTransitioning ? PointerEvents.NONE : PointerEvents.AUTO;
}
@Override
public void setLayerType(int layerType, @Nullable Paint paint) {
// ignore – layer type is controlled by `transitioning` prop
}
public void setNeedsOffscreenAlphaCompositing(boolean needsOffscreenAlphaCompositing) {
// ignore - offscreen alpha is controlled by `transitioning` prop
}
protected void setContainer(@Nullable ScreenContainer mContainer) {
this.mContainer = mContainer;
}
protected @Nullable ScreenContainer getContainer() {
return mContainer;
}
protected Fragment getFragment() {
return mFragment;
}
public void setActive(boolean active) {
if (active == mActive) {
return;
}
mActive = active;
if (mContainer != null) {
mContainer.notifyChildUpdate();
}
}
public boolean isActive() {
return mActive;
}
}