-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLayoutDirection.java
More file actions
62 lines (52 loc) · 1.61 KB
/
LayoutDirection.java
File metadata and controls
62 lines (52 loc) · 1.61 KB
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
package com.reactnativenavigation.options;
import android.text.TextUtils;
import android.view.View;
import java.util.Locale;
public enum LayoutDirection {
RTL(View.LAYOUT_DIRECTION_RTL),
LTR(View.LAYOUT_DIRECTION_LTR),
LOCALE(View.LAYOUT_DIRECTION_LOCALE),
DEFAULT(View.LAYOUT_DIRECTION_LTR);
private final int direction;
LayoutDirection(int direction) {
this.direction = direction;
}
public static LayoutDirection fromString(String direction) {
switch (direction) {
case "rtl":
return RTL;
case "ltr":
return LTR;
case "locale":
return LOCALE;
default:
return DEFAULT;
}
}
public boolean hasValue() {
return this != DEFAULT;
}
public int get() {
return switch (direction) {
case View.LAYOUT_DIRECTION_RTL -> RTL.direction;
case View.LAYOUT_DIRECTION_LTR -> LTR.direction;
case View.LAYOUT_DIRECTION_LOCALE -> LOCALE.direction;
default -> DEFAULT.direction;
};
}
public int inverse() {
return (isRtl() ? LTR : RTL).direction;
}
public boolean isRtl() {
switch (direction) {
case View.LAYOUT_DIRECTION_LTR:
return false;
case View.LAYOUT_DIRECTION_RTL:
return true;
case View.LAYOUT_DIRECTION_LOCALE:
return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
default:
return false;
}
}
}