66import android .graphics .Color ;
77import android .os .Bundle ;
88import android .provider .Browser ;
9+ import android .support .annotation .NonNull ;
910import android .support .customtabs .CustomTabsIntent ;
1011import android .text .TextUtils ;
1112import com .droibit .android .customtabs .launcher .CustomTabsLauncher ;
2223import com .facebook .react .common .annotations .VisibleForTesting ;
2324import java .util .Map ;
2425import java .util .regex .Pattern ;
25- import javax .annotation .Nullable ;
2626
2727/**
2828 * CustomTabs module.
@@ -41,17 +41,23 @@ public class CustomTabsModule extends ReactContextBaseJavaModule {
4141 private static final String KEY_ANIMATION_END_ENTER = "endEnter" ;
4242 private static final String KEY_ANIMATION_END_EXIT = "endExit" ;
4343
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+
4451 private static final Map <String , Object > CONSTANTS ;
4552
4653 static {
4754 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" );
5561 }
5662
5763 private static final String MODULE_NAME = "CustomTabsManager" ;
@@ -69,8 +75,6 @@ public String getName() {
6975 return MODULE_NAME ;
7076 }
7177
72- @ Nullable
73- @ Override
7478 public Map <String , Object > getConstants () {
7579 return CONSTANTS ;
7680 }
@@ -115,8 +119,7 @@ public void openURL(String url, ReadableMap option, Promise promise) {
115119 }
116120 }
117121
118- @ VisibleForTesting
119- CustomTabsIntent buildIntent (Context context ,
122+ private CustomTabsIntent buildIntent (Context context ,
120123 CustomTabsIntent .Builder builder ,
121124 ReadableMap option ) {
122125 if (option .hasKey (KEY_TOOLBAR_COLOR )) {
@@ -140,8 +143,6 @@ CustomTabsIntent buildIntent(Context context,
140143 builder .addDefaultShareMenuItem ();
141144 }
142145
143- // TODO: If it does not launch Chrome, animation is unnecessary?
144-
145146 if (option .hasKey (KEY_ANIMATIONS )) {
146147 final ReadableMap animations = option .getMap (KEY_ANIMATIONS );
147148 applyAnimation (context , builder , animations );
@@ -182,35 +183,35 @@ CustomTabsIntent buildIntent(Context context,
182183 return customTabsIntent ;
183184 }
184185
185- @ VisibleForTesting
186- boolean httpOrHttpsScheme (String url ) {
186+ private boolean httpOrHttpsScheme (String url ) {
187187 return url .startsWith ("http" ) || url .startsWith ("https" );
188188 }
189189
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 )
194195 ? resolveAnimationIdentifierIfNeeded (context ,
195- animations .getString (KEY_ANIMATION_START_ENTER ))
196+ srcAnimations .getString (KEY_ANIMATION_START_ENTER ))
196197 : -1 ;
197- final int startExitAnimationId = animations .hasKey (KEY_ANIMATION_START_EXIT )
198+ final int startExitAnimationId = srcAnimations .hasKey (KEY_ANIMATION_START_EXIT )
198199 ? resolveAnimationIdentifierIfNeeded (context ,
199- animations .getString (KEY_ANIMATION_START_EXIT ))
200+ srcAnimations .getString (KEY_ANIMATION_START_EXIT ))
200201 : -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 ))
203204 : -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 ))
206207 : -1 ;
207208
208209 if (startEnterAnimationId != -1 && startExitAnimationId != -1 ) {
209- builder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId );
210+ destBuilder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId );
210211 }
211212
212213 if (endEnterAnimationId != -1 && endExitAnimationId != -1 ) {
213- builder .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
214+ destBuilder .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
214215 }
215216 }
216217
0 commit comments