6
6
import android .graphics .Color ;
7
7
import android .os .Bundle ;
8
8
import android .provider .Browser ;
9
+ import android .support .annotation .NonNull ;
9
10
import android .support .customtabs .CustomTabsIntent ;
10
11
import android .text .TextUtils ;
11
12
import com .droibit .android .customtabs .launcher .CustomTabsLauncher ;
22
23
import com .facebook .react .common .annotations .VisibleForTesting ;
23
24
import java .util .Map ;
24
25
import java .util .regex .Pattern ;
25
- import javax .annotation .Nullable ;
26
26
27
27
/**
28
28
* CustomTabs module.
@@ -41,17 +41,23 @@ public class CustomTabsModule extends ReactContextBaseJavaModule {
41
41
private static final String KEY_ANIMATION_END_ENTER = "endEnter" ;
42
42
private static final String KEY_ANIMATION_END_EXIT = "endExit" ;
43
43
44
+ private static final String ANIMATION_SLIDE_IN_RIGHT = "ANIMATION_SLIDE_IN_RIGHT" ;
45
+ private static final String ANIMATION_SLIDE_OUT_RIGHT = "ANIMATION_SLIDE_OUT_RIGHT" ;
46
+ private static final String ANIMATION_SLIDE_IN_LEFT = "ANIMATION_SLIDE_IN_LEFT" ;
47
+ private static final String ANIMATION_SLIDE_OUT_LEFT = "ANIMATION_SLIDE_OUT_LEFT" ;
48
+ private static final String ANIMATION_FADE_IN = "ANIMATION_FADE_IN" ;
49
+ private static final String ANIMATION_FADE_OUT = "ANIMATION_FADE_OUT" ;
50
+
44
51
private static final Map <String , Object > CONSTANTS ;
45
52
46
53
static {
47
54
CONSTANTS = MapBuilder .newHashMap ();
48
- CONSTANTS .put (KEY_TOOLBAR_COLOR , KEY_TOOLBAR_COLOR );
49
- CONSTANTS .put (KEY_ENABLE_URL_BAR_HIDING , KEY_ENABLE_URL_BAR_HIDING );
50
- CONSTANTS .put (KEY_SHOW_PAGE_TITLE , KEY_SHOW_PAGE_TITLE );
51
- CONSTANTS .put (KEY_DEFAULT_SHARE_MENU_ITEM , KEY_DEFAULT_SHARE_MENU_ITEM );
52
- CONSTANTS .put (KEY_ANIMATIONS , KEY_ANIMATIONS );
53
- CONSTANTS .put (KEY_HEADERS , KEY_HEADERS );
54
- CONSTANTS .put (KEY_FORCE_CLOSE_ON_REDIRECTION , KEY_FORCE_CLOSE_ON_REDIRECTION );
55
+ CONSTANTS .put (ANIMATION_SLIDE_IN_RIGHT , "slide_in_right" );
56
+ CONSTANTS .put (ANIMATION_SLIDE_OUT_RIGHT , "android:anim/slide_out_right" );
57
+ CONSTANTS .put (ANIMATION_SLIDE_IN_LEFT , "android:anim/slide_in_left" );
58
+ CONSTANTS .put (ANIMATION_SLIDE_OUT_LEFT , "slide_out_left" );
59
+ CONSTANTS .put (ANIMATION_FADE_IN , "android:anim/fade_in" );
60
+ CONSTANTS .put (ANIMATION_FADE_OUT , "android:anim/fade_out" );
55
61
}
56
62
57
63
private static final String MODULE_NAME = "CustomTabsManager" ;
@@ -69,8 +75,6 @@ public String getName() {
69
75
return MODULE_NAME ;
70
76
}
71
77
72
- @ Nullable
73
- @ Override
74
78
public Map <String , Object > getConstants () {
75
79
return CONSTANTS ;
76
80
}
@@ -115,8 +119,7 @@ public void openURL(String url, ReadableMap option, Promise promise) {
115
119
}
116
120
}
117
121
118
- @ VisibleForTesting
119
- CustomTabsIntent buildIntent (Context context ,
122
+ private CustomTabsIntent buildIntent (Context context ,
120
123
CustomTabsIntent .Builder builder ,
121
124
ReadableMap option ) {
122
125
if (option .hasKey (KEY_TOOLBAR_COLOR )) {
@@ -140,8 +143,6 @@ CustomTabsIntent buildIntent(Context context,
140
143
builder .addDefaultShareMenuItem ();
141
144
}
142
145
143
- // TODO: If it does not launch Chrome, animation is unnecessary?
144
-
145
146
if (option .hasKey (KEY_ANIMATIONS )) {
146
147
final ReadableMap animations = option .getMap (KEY_ANIMATIONS );
147
148
applyAnimation (context , builder , animations );
@@ -182,35 +183,35 @@ CustomTabsIntent buildIntent(Context context,
182
183
return customTabsIntent ;
183
184
}
184
185
185
- @ VisibleForTesting
186
- boolean httpOrHttpsScheme (String url ) {
186
+ private boolean httpOrHttpsScheme (String url ) {
187
187
return url .startsWith ("http" ) || url .startsWith ("https" );
188
188
}
189
189
190
- @ VisibleForTesting
191
- void applyAnimation (Context context , CustomTabsIntent .Builder builder ,
192
- ReadableMap animations ) {
193
- final int startEnterAnimationId = animations .hasKey (KEY_ANIMATION_START_ENTER )
190
+ private void applyAnimation (
191
+ @ NonNull Context context ,
192
+ @ NonNull CustomTabsIntent .Builder destBuilder ,
193
+ @ NonNull ReadableMap srcAnimations ) {
194
+ final int startEnterAnimationId = srcAnimations .hasKey (KEY_ANIMATION_START_ENTER )
194
195
? resolveAnimationIdentifierIfNeeded (context ,
195
- animations .getString (KEY_ANIMATION_START_ENTER ))
196
+ srcAnimations .getString (KEY_ANIMATION_START_ENTER ))
196
197
: -1 ;
197
- final int startExitAnimationId = animations .hasKey (KEY_ANIMATION_START_EXIT )
198
+ final int startExitAnimationId = srcAnimations .hasKey (KEY_ANIMATION_START_EXIT )
198
199
? resolveAnimationIdentifierIfNeeded (context ,
199
- animations .getString (KEY_ANIMATION_START_EXIT ))
200
+ srcAnimations .getString (KEY_ANIMATION_START_EXIT ))
200
201
: -1 ;
201
- final int endEnterAnimationId = animations .hasKey (KEY_ANIMATION_END_ENTER )
202
- ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_END_ENTER ))
202
+ final int endEnterAnimationId = srcAnimations .hasKey (KEY_ANIMATION_END_ENTER )
203
+ ? resolveAnimationIdentifierIfNeeded (context , srcAnimations .getString (KEY_ANIMATION_END_ENTER ))
203
204
: -1 ;
204
- final int endExitAnimationId = animations .hasKey (KEY_ANIMATION_END_EXIT )
205
- ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_END_EXIT ))
205
+ final int endExitAnimationId = srcAnimations .hasKey (KEY_ANIMATION_END_EXIT )
206
+ ? resolveAnimationIdentifierIfNeeded (context , srcAnimations .getString (KEY_ANIMATION_END_EXIT ))
206
207
: -1 ;
207
208
208
209
if (startEnterAnimationId != -1 && startExitAnimationId != -1 ) {
209
- builder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId );
210
+ destBuilder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId );
210
211
}
211
212
212
213
if (endEnterAnimationId != -1 && endExitAnimationId != -1 ) {
213
- builder .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
214
+ destBuilder .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
214
215
}
215
216
}
216
217
0 commit comments