32
32
*/
33
33
public class CustomTabsModule extends ReactContextBaseJavaModule {
34
34
35
- @ VisibleForTesting
36
- /* package */ static final String KEY_TOOLBAR_COLOR = "toolbarColor" ;
37
- @ VisibleForTesting
38
- /* package */ static final String KEY_ENABLE_URL_BAR_HIDING = "enableUrlBarHiding" ;
39
- @ VisibleForTesting
40
- /* package */ static final String KEY_SHOW_PAGE_TITLE = "showPageTitle" ;
41
- @ VisibleForTesting
42
- /* package */ static final String KEY_DEFAULT_SHARE_MENU_ITEM = "enableDefaultShare" ;
43
- @ VisibleForTesting
44
- /* package */ static final String KEY_ANIMATIONS = "animations" ;
45
- @ VisibleForTesting
46
- /* package */ static final String KEY_HEADERS = "headers" ;
47
- @ VisibleForTesting
48
- /* package */ static final String FORCE_CLOSE_ON_REDIRECTION = "forceCloseOnRedirection" ;
35
+ private static final String KEY_TOOLBAR_COLOR = "toolbarColor" ;
36
+ private static final String KEY_ENABLE_URL_BAR_HIDING = "enableUrlBarHiding" ;
37
+ private static final String KEY_SHOW_PAGE_TITLE = "showPageTitle" ;
38
+ private static final String KEY_DEFAULT_SHARE_MENU_ITEM = "enableDefaultShare" ;
39
+ private static final String KEY_ANIMATIONS = "animations" ;
40
+ private static final String KEY_HEADERS = "headers" ;
41
+ private static final String KEY_FORCE_CLOSE_ON_REDIRECTION = "forceCloseOnRedirection" ;
42
+ private static final String KEY_ANIMATION_START_ENTER = "startEnter" ;
43
+ private static final String KEY_ANIMATION_START_EXIT = "startExit" ;
44
+ private static final String KEY_ANIMATION_END_ENTER = "endEnter" ;
45
+ private static final String KEY_ANIMATION_END_EXIT = "endExit" ;
49
46
50
47
private static final Map <String , Object > CONSTANTS ;
51
48
@@ -57,7 +54,7 @@ public class CustomTabsModule extends ReactContextBaseJavaModule {
57
54
CONSTANTS .put (KEY_DEFAULT_SHARE_MENU_ITEM , KEY_DEFAULT_SHARE_MENU_ITEM );
58
55
CONSTANTS .put (KEY_ANIMATIONS , KEY_ANIMATIONS );
59
56
CONSTANTS .put (KEY_HEADERS , KEY_HEADERS );
60
- CONSTANTS .put (FORCE_CLOSE_ON_REDIRECTION , FORCE_CLOSE_ON_REDIRECTION );
57
+ CONSTANTS .put (KEY_FORCE_CLOSE_ON_REDIRECTION , KEY_FORCE_CLOSE_ON_REDIRECTION );
61
58
}
62
59
63
60
private static final String MODULE_NAME = "CustomTabsManager" ;
@@ -178,8 +175,8 @@ public void openURL(String url, ReadableMap option, Promise promise) {
178
175
}
179
176
}
180
177
181
- if (option .hasKey (FORCE_CLOSE_ON_REDIRECTION ) &&
182
- option .getBoolean (FORCE_CLOSE_ON_REDIRECTION )) {
178
+ if (option .hasKey (KEY_FORCE_CLOSE_ON_REDIRECTION ) &&
179
+ option .getBoolean (KEY_FORCE_CLOSE_ON_REDIRECTION )) {
183
180
customTabsIntent .intent .addFlags (Intent .FLAG_ACTIVITY_NO_HISTORY );
184
181
customTabsIntent .intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
185
182
}
@@ -194,24 +191,30 @@ public void openURL(String url, ReadableMap option, Promise promise) {
194
191
195
192
@ VisibleForTesting
196
193
/* package */ void applyAnimation (Context context , CustomTabsIntent .Builder builder , ReadableMap animations ) {
197
- final int startEnterAnimationId = animations .hasKey ("startEnter" )
198
- ? resolveAnimationIdentifierIfNeed (context , animations .getString ("startEnter" ))
199
- : 0 ;
200
- final int startExitAnimationId = animations .hasKey ("startExit" )
201
- ? resolveAnimationIdentifierIfNeed (context , animations .getString ("startExit" ))
202
- : 0 ;
203
- final int endEnterAnimationId = animations .hasKey ("endEnter" )
204
- ? resolveAnimationIdentifierIfNeed (context , animations .getString ("endEnter" ))
205
- : 0 ;
206
- final int endExitAnimationId = animations .hasKey ("endExit" )
207
- ? resolveAnimationIdentifierIfNeed (context , animations .getString ("endExit" ))
208
- : 0 ;
209
- builder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId )
210
- .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
194
+ final int startEnterAnimationId = animations .hasKey (KEY_ANIMATION_START_ENTER )
195
+ ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_START_ENTER ))
196
+ : -1 ;
197
+ final int startExitAnimationId = animations .hasKey (KEY_ANIMATION_START_EXIT )
198
+ ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_START_EXIT ))
199
+ : -1 ;
200
+ final int endEnterAnimationId = animations .hasKey (KEY_ANIMATION_END_ENTER )
201
+ ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_END_ENTER ))
202
+ : -1 ;
203
+ final int endExitAnimationId = animations .hasKey (KEY_ANIMATION_END_EXIT )
204
+ ? resolveAnimationIdentifierIfNeeded (context , animations .getString (KEY_ANIMATION_END_EXIT ))
205
+ : -1 ;
206
+
207
+ if (startEnterAnimationId != -1 && startExitAnimationId != -1 ) {
208
+ builder .setStartAnimations (context , startEnterAnimationId , startExitAnimationId );
209
+ }
210
+
211
+ if (endEnterAnimationId != -1 && endExitAnimationId != -1 ) {
212
+ builder .setExitAnimations (context , endEnterAnimationId , endExitAnimationId );
213
+ }
211
214
}
212
215
213
216
// Complement the application name of the resource qualifier as necessary.
214
- private int resolveAnimationIdentifierIfNeed (Context context , String identifier ) {
217
+ private int resolveAnimationIdentifierIfNeeded (Context context , String identifier ) {
215
218
if (animationIdentifierPattern .matcher (identifier ).find ()) {
216
219
return context .getResources ().getIdentifier (identifier , null , null );
217
220
} else {
0 commit comments