|
@@ -1,34 +1,32 @@
|
1
|
1
|
package com.reactnativenavigation.presentation;
|
2
|
2
|
|
3
|
3
|
|
4
|
|
-import androidx.annotation.NonNull;
|
5
|
4
|
import android.view.Gravity;
|
6
|
5
|
import android.view.View;
|
7
|
6
|
import android.view.ViewGroup;
|
8
|
|
-import android.widget.FrameLayout;
|
9
|
|
-import android.widget.RelativeLayout;
|
10
|
7
|
|
11
|
8
|
import com.reactnativenavigation.R;
|
12
|
9
|
import com.reactnativenavigation.parse.FabOptions;
|
|
10
|
+import com.reactnativenavigation.viewcontrollers.ViewController;
|
13
|
11
|
import com.reactnativenavigation.views.Fab;
|
14
|
12
|
import com.reactnativenavigation.views.FabMenu;
|
15
|
|
-import com.reactnativenavigation.views.ReactComponent;
|
16
|
13
|
|
17
|
|
-import static android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM;
|
18
|
|
-import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
|
19
|
|
-import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
|
20
|
|
-import static android.widget.RelativeLayout.ALIGN_PARENT_TOP;
|
|
14
|
+import androidx.annotation.NonNull;
|
|
15
|
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
16
|
+
|
|
17
|
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
21
|
18
|
import static com.github.clans.fab.FloatingActionButton.SIZE_MINI;
|
22
|
19
|
import static com.github.clans.fab.FloatingActionButton.SIZE_NORMAL;
|
|
20
|
+import static com.reactnativenavigation.utils.ObjectUtils.perform;
|
23
|
21
|
|
24
|
22
|
public class FabPresenter {
|
25
|
23
|
private ViewGroup viewGroup;
|
26
|
|
- private ReactComponent component;
|
|
24
|
+ private ViewController component;
|
27
|
25
|
|
28
|
26
|
private Fab fab;
|
29
|
27
|
private FabMenu fabMenu;
|
30
|
28
|
|
31
|
|
- public void applyOptions(FabOptions options, @NonNull ReactComponent component, @NonNull ViewGroup viewGroup) {
|
|
29
|
+ public void applyOptions(FabOptions options, @NonNull ViewController component, @NonNull ViewGroup viewGroup) {
|
32
|
30
|
this.viewGroup = viewGroup;
|
33
|
31
|
this.component = component;
|
34
|
32
|
|
|
@@ -51,10 +49,9 @@ public class FabPresenter {
|
51
|
49
|
}
|
52
|
50
|
}
|
53
|
51
|
|
54
|
|
- public void mergeOptions(FabOptions options, @NonNull ReactComponent component, @NonNull ViewGroup viewGroup) {
|
|
52
|
+ public void mergeOptions(FabOptions options, @NonNull ViewController component, @NonNull ViewGroup viewGroup) {
|
55
|
53
|
this.viewGroup = viewGroup;
|
56
|
54
|
this.component = component;
|
57
|
|
-
|
58
|
55
|
if (options.id.hasValue()) {
|
59
|
56
|
if (fabMenu != null && fabMenu.getFabId().equals(options.id.get())) {
|
60
|
57
|
mergeParams(fabMenu, options);
|
|
@@ -103,139 +100,44 @@ public class FabPresenter {
|
103
|
100
|
}
|
104
|
101
|
|
105
|
102
|
private void setParams(View fab, FabOptions options) {
|
106
|
|
- ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
107
|
|
- if (viewGroup instanceof RelativeLayout) {
|
108
|
|
- RelativeLayout.LayoutParams layoutParamsRelative = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
109
|
|
- layoutParamsRelative.bottomMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
110
|
|
- layoutParamsRelative.rightMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
111
|
|
- layoutParamsRelative.leftMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
112
|
|
- layoutParamsRelative.topMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
113
|
|
- if (options.alignHorizontally.hasValue()) {
|
114
|
|
- if ("right".equals(options.alignHorizontally.get())) {
|
115
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_LEFT);
|
116
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_RIGHT);
|
117
|
|
- }
|
118
|
|
- if ("left".equals(options.alignHorizontally.get())) {
|
119
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_RIGHT);
|
120
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_LEFT);
|
121
|
|
- }
|
122
|
|
- } else {
|
123
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_RIGHT);
|
|
103
|
+ CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
|
|
104
|
+ lp.rightMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
|
105
|
+ lp.leftMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
|
106
|
+ lp.bottomMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
|
107
|
+ fab.setTag(R.id.fab_bottom_margin, lp.bottomMargin);
|
|
108
|
+ lp.gravity = Gravity.BOTTOM;
|
|
109
|
+ if (options.alignHorizontally.hasValue()) {
|
|
110
|
+ if ("right".equals(options.alignHorizontally.get())) {
|
|
111
|
+ lp.gravity |= Gravity.RIGHT;
|
124
|
112
|
}
|
125
|
|
- if (options.alignVertically.hasValue()) {
|
126
|
|
- if ("top".equals(options.alignVertically.get())) {
|
127
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_BOTTOM);
|
128
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_TOP);
|
129
|
|
- }
|
130
|
|
- if ("bottom".equals(options.alignVertically.get())) {
|
131
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_TOP);
|
132
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_BOTTOM);
|
133
|
|
- }
|
134
|
|
- } else {
|
135
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_BOTTOM);
|
|
113
|
+ if ("left".equals(options.alignHorizontally.get())) {
|
|
114
|
+ lp.gravity |= Gravity.LEFT;
|
136
|
115
|
}
|
137
|
|
- layoutParams = layoutParamsRelative;
|
138
|
|
- }
|
139
|
|
- if (viewGroup instanceof FrameLayout) {
|
140
|
|
- FrameLayout.LayoutParams layoutParamsFrame = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
141
|
|
- layoutParamsFrame.bottomMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
142
|
|
- layoutParamsFrame.rightMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
143
|
|
- layoutParamsFrame.leftMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
144
|
|
- layoutParamsFrame.topMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
145
|
|
- if (options.alignHorizontally.hasValue()) {
|
146
|
|
- if ("right".equals(options.alignHorizontally.get())) {
|
147
|
|
- removeGravityParam(layoutParamsFrame, Gravity.LEFT);
|
148
|
|
- setGravityParam(layoutParamsFrame, Gravity.RIGHT);
|
149
|
|
- }
|
150
|
|
- if ("left".equals(options.alignHorizontally.get())) {
|
151
|
|
- removeGravityParam(layoutParamsFrame, Gravity.RIGHT);
|
152
|
|
- setGravityParam(layoutParamsFrame, Gravity.LEFT);
|
153
|
|
- }
|
154
|
|
- } else {
|
155
|
|
- setGravityParam(layoutParamsFrame, Gravity.RIGHT);
|
156
|
|
- }
|
157
|
|
- if (options.alignVertically.hasValue()) {
|
158
|
|
- if ("top".equals(options.alignVertically.get())) {
|
159
|
|
- removeGravityParam(layoutParamsFrame, Gravity.BOTTOM);
|
160
|
|
- setGravityParam(layoutParamsFrame, Gravity.TOP);
|
161
|
|
- }
|
162
|
|
- if ("bottom".equals(options.alignVertically.get())) {
|
163
|
|
- removeGravityParam(layoutParamsFrame, Gravity.TOP);
|
164
|
|
- setGravityParam(layoutParamsFrame, Gravity.BOTTOM);
|
165
|
|
- }
|
166
|
|
- } else {
|
167
|
|
- setGravityParam(layoutParamsFrame, Gravity.BOTTOM);
|
168
|
|
- }
|
169
|
|
- layoutParams = layoutParamsFrame;
|
|
116
|
+ } else {
|
|
117
|
+ lp.gravity |= Gravity.RIGHT;
|
170
|
118
|
}
|
171
|
|
- fab.setLayoutParams(layoutParams);
|
|
119
|
+ fab.setLayoutParams(lp);
|
172
|
120
|
}
|
173
|
121
|
|
174
|
122
|
private void mergeParams(View fab, FabOptions options) {
|
175
|
|
- ViewGroup.LayoutParams layoutParams = fab.getLayoutParams();
|
176
|
|
- if (viewGroup instanceof RelativeLayout) {
|
177
|
|
- RelativeLayout.LayoutParams layoutParamsRelative = (RelativeLayout.LayoutParams) fab.getLayoutParams();
|
178
|
|
- if (layoutParamsRelative == null) {
|
179
|
|
- layoutParamsRelative = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
180
|
|
- layoutParamsRelative.bottomMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
181
|
|
- layoutParamsRelative.rightMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
182
|
|
- layoutParamsRelative.leftMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
183
|
|
- layoutParamsRelative.topMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
|
123
|
+ CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) perform(
|
|
124
|
+ fab,
|
|
125
|
+ new CoordinatorLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT),
|
|
126
|
+ View::getLayoutParams
|
|
127
|
+ );
|
|
128
|
+ fab.setTag(R.id.fab_bottom_margin, lp.leftMargin);
|
|
129
|
+ lp.gravity = Gravity.BOTTOM;
|
|
130
|
+ if (options.alignHorizontally.hasValue()) {
|
|
131
|
+ if ("right".equals(options.alignHorizontally.get())) {
|
|
132
|
+ lp.gravity |= Gravity.RIGHT;
|
184
|
133
|
}
|
185
|
|
- if (options.alignHorizontally.hasValue()) {
|
186
|
|
- if ("right".equals(options.alignHorizontally.get())) {
|
187
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_LEFT);
|
188
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_RIGHT);
|
189
|
|
- }
|
190
|
|
- if ("left".equals(options.alignHorizontally.get())) {
|
191
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_RIGHT);
|
192
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_LEFT);
|
193
|
|
- }
|
|
134
|
+ if ("left".equals(options.alignHorizontally.get())) {
|
|
135
|
+ lp.gravity |= Gravity.RIGHT;
|
194
|
136
|
}
|
195
|
|
- if (options.alignVertically.hasValue()) {
|
196
|
|
- if ("top".equals(options.alignVertically.get())) {
|
197
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_BOTTOM);
|
198
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_TOP);
|
199
|
|
- }
|
200
|
|
- if ("bottom".equals(options.alignVertically.get())) {
|
201
|
|
- layoutParamsRelative.removeRule(ALIGN_PARENT_TOP);
|
202
|
|
- layoutParamsRelative.addRule(ALIGN_PARENT_BOTTOM);
|
203
|
|
- }
|
204
|
|
- }
|
205
|
|
- layoutParams = layoutParamsRelative;
|
206
|
|
- }
|
207
|
|
- if (viewGroup instanceof FrameLayout) {
|
208
|
|
- FrameLayout.LayoutParams layoutParamsFrame = (FrameLayout.LayoutParams) fab.getLayoutParams();
|
209
|
|
- if (layoutParamsFrame == null) {
|
210
|
|
- layoutParamsFrame = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
211
|
|
- layoutParamsFrame.bottomMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
212
|
|
- layoutParamsFrame.rightMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
213
|
|
- layoutParamsFrame.leftMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
214
|
|
- layoutParamsFrame.topMargin = (int) viewGroup.getContext().getResources().getDimension(R.dimen.margin);
|
215
|
|
- }
|
216
|
|
- if (options.alignHorizontally.hasValue()) {
|
217
|
|
- if ("right".equals(options.alignHorizontally.get())) {
|
218
|
|
- removeGravityParam(layoutParamsFrame, Gravity.LEFT);
|
219
|
|
- setGravityParam(layoutParamsFrame, Gravity.RIGHT);
|
220
|
|
- }
|
221
|
|
- if ("left".equals(options.alignHorizontally.get())) {
|
222
|
|
- removeGravityParam(layoutParamsFrame, Gravity.RIGHT);
|
223
|
|
- setGravityParam(layoutParamsFrame, Gravity.LEFT);
|
224
|
|
- }
|
225
|
|
- }
|
226
|
|
- if (options.alignVertically.hasValue()) {
|
227
|
|
- if ("top".equals(options.alignVertically.get())) {
|
228
|
|
- removeGravityParam(layoutParamsFrame, Gravity.BOTTOM);
|
229
|
|
- setGravityParam(layoutParamsFrame, Gravity.TOP);
|
230
|
|
- }
|
231
|
|
- if ("bottom".equals(options.alignVertically.get())) {
|
232
|
|
- removeGravityParam(layoutParamsFrame, Gravity.TOP);
|
233
|
|
- setGravityParam(layoutParamsFrame, Gravity.BOTTOM);
|
234
|
|
- }
|
235
|
|
- }
|
236
|
|
- layoutParams = layoutParamsFrame;
|
|
137
|
+ } else {
|
|
138
|
+ lp.gravity |= Gravity.RIGHT;
|
237
|
139
|
}
|
238
|
|
- fab.setLayoutParams(layoutParams);
|
|
140
|
+ fab.setLayoutParams(lp);
|
239
|
141
|
}
|
240
|
142
|
|
241
|
143
|
private void applyFabOptions(Fab fab, FabOptions options) {
|
|
@@ -373,14 +275,4 @@ public class FabPresenter {
|
373
|
275
|
fabMenu.disableCollapse();
|
374
|
276
|
}
|
375
|
277
|
}
|
376
|
|
-
|
377
|
|
- private void setGravityParam(FrameLayout.LayoutParams params, int gravityParam) {
|
378
|
|
- params.gravity = params.gravity | gravityParam;
|
379
|
|
- }
|
380
|
|
-
|
381
|
|
- private void removeGravityParam(FrameLayout.LayoutParams params, int gravityParam) {
|
382
|
|
- if ((params.gravity & gravityParam) == gravityParam) {
|
383
|
|
- params.gravity = params.gravity & ~gravityParam;
|
384
|
|
- }
|
385
|
|
- }
|
386
|
278
|
}
|