UNPKG

8.16 kBMarkdownView Raw
1<!--
2# license: Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18-->
19
20[![Build Status](https://travis-ci.org/apache/cordova-plugin-splashscreen.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-splashscreen)
21
22# cordova-plugin-splashscreen
23
24This plugin displays and hides a splash screen during application launch.
25
26Report issues with this plugin on the [Apache Cordova issue tracker][Apache Cordova issue tracker].
27
28## Installation
29
30 // npm hosted (new) id
31 cordova plugin add cordova-plugin-splashscreen
32
33 // you may also install directly from this repo
34 cordova plugin add https://github.com/apache/cordova-plugin-splashscreen.git
35
36## Supported Platforms
37
38- Amazon Fire OS
39- Android
40- BlackBerry 10
41- iOS
42- Windows Phone 7 and 8
43- Windows 8
44- Windows
45- Browser
46
47## Preferences
48
49#### config.xml
50
51- __SplashScreen__ (string). The resource name which is used for the displaying splash screen. Different platforms use values for this.
52
53 <preference name="SplashScreen" value="resourcename" />
54
55- __AutoHideSplashScreen__ (boolean, default to `true`). Indicates wherether hide splash screen automatically or not. Splash screen hidden after amount of time specified in the `SplashScreenDelay` preference.
56
57 <preference name="AutoHideSplashScreen" value="true" />
58
59- __SplashScreenDelay__ (number, default to 3000). Amount of time in milliseconds to wait before automatically hide splash screen.
60
61 <preference name="SplashScreenDelay" value="3000" />
62
63
64### Android Quirks
65
66In your `config.xml`, you need to add the following preferences:
67
68 <preference name="SplashScreen" value="foo" />
69 <preference name="SplashScreenDelay" value="3000" />
70 <preference name="SplashMaintainAspectRatio" value="true|false" />
71 <preference name="SplashShowOnlyFirstTime" value="true|false" />
72
73Where foo is the name of the splashscreen file, preferably a 9 patch file. Make sure to add your splashcreen files to your res/xml directory under the appropriate folders. The second parameter represents how long the splashscreen will appear in milliseconds. It defaults to 3000 ms. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html)
74for more information.
75
76"SplashMaintainAspectRatio" preference is optional. If set to true, splash screen drawable is not stretched to fit screen, but instead simply "covers" the screen, like CSS "background-size:cover". This is very useful when splash screen images cannot be distorted in any way, for example when they contain scenery or text. This setting works best with images that have large margins (safe areas) that can be safely cropped on screens with different aspect ratios.
77
78The plugin reloads splash drawable whenever orientation changes, so you can specify different drawables for portrait and landscape orientations.
79
80"SplashShowOnlyFirstTime" preference is also optional and defaults to `true`. When set to `true` splash screen will only appear on application launch. However, if you plan to use `navigator.app.exitApp()` to close application and force splash screen appear on next launch, you should set this property to `false` (this also applies to closing the App with Back button).
81
82### Browser Quirks
83
84You can use the following preferences in your `config.xml`:
85
86 <platform name="browser">
87 <preference name="SplashScreen" value="/images/browser/splashscreen.jpg" /> <!-- defaults to "/img/logo.png" -->
88 <preference name="SplashScreenDelay" value="3000" /> <!-- defaults to "3000" -->
89 <preference name="SplashScreenBackgroundColor" value="green" /> <!-- defaults to "#464646" -->
90 <preference name="ShowSplashScreen" value="false" /> <!-- defaults to "true" -->
91 <preference name="SplashScreenWidth" value="600" /> <!-- defaults to "170" -->
92 <preference name="SplashScreenHeight" value="300" /> <!-- defaults to "200" -->
93 </platform>
94
95__Note__: `SplashScreen` value should be absolute in order to work in a sub-page.
96
97### Android and iOS Quirks
98
99- `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to
100 prevent the splash screen from fading in and out when its display
101 state changes.
102
103 <preference name="FadeSplashScreen" value="false"/>
104
105- `FadeSplashScreenDuration` (float, defaults to `3000`): Specifies the
106 number of milliseconds for the splash screen fade effect to execute.
107
108 <preference name="FadeSplashScreenDuration" value="3000"/>
109
110Note also that this value used to be seconds, and not milliseconds, so values less than 30 will still be treated as seconds. ( Consider this a deprecated patch that will disapear in some future version. )
111
112_Note_: `FadeSplashScreenDuration` is included into `SplashScreenDelay`, for example if you have `<preference name="SplashScreenDelay" value="3000" />` and `<preference name="FadeSplashScreenDuration" value="1000"/>` defined in `config.xml`:
113
114- 00:00 - splashscreen is shown
115- 00:02 - fading has started
116- 00:03 - splashscreen is hidden
117
118Turning the fading off via `<preference name="FadeSplashScreen" value="false"/>` technically means fading duration to be `0` so that in this example the overall splash delay will still be 3 seconds.
119
120_Note_: This only applies to the app startup - you need to take the fading timeout into account when manually showing/hiding the splashscreen in the code:
121
122```javascript
123navigator.splashscreen.show();
124window.setTimeout(function () {
125 navigator.splashscreen.hide();
126}, splashDuration - fadeDuration);
127```
128
129- `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false`
130 to hide the splash-screen spinner.
131
132 <preference name="ShowSplashScreenSpinner" value="false"/>
133
134## Methods
135
136- splashscreen.show
137- splashscreen.hide
138
139## splashscreen.hide
140
141Dismiss the splash screen.
142
143 navigator.splashscreen.hide();
144
145
146### BlackBerry 10, WP8, iOS Quirk
147
148The `config.xml` file's `AutoHideSplashScreen` setting must be
149`false`. To delay hiding the splash screen for two seconds, add a
150timer such as the following in the `deviceready` event handler:
151
152 setTimeout(function() {
153 navigator.splashscreen.hide();
154 }, 2000);
155
156## splashscreen.show
157
158Displays the splash screen.
159
160 navigator.splashscreen.show();
161
162
163Your application cannot call `navigator.splashscreen.show()` until the app has
164started and the `deviceready` event has fired. But since typically the splash
165screen is meant to be visible before your app has started, that would seem to
166defeat the purpose of the splash screen. Providing some configuration in
167`config.xml` will automatically `show` the splash screen immediately after your
168app launch and before it has fully started and received the `deviceready`
169event. See [Icons and Splash Screens](http://cordova.apache.org/docs/en/edge/config_ref_images.md.html)
170for more information on doing this configuration. For this reason, it is
171unlikely you need to call `navigator.splashscreen.show()` to make the splash
172screen visible for app startup.
173
174[Apache Cordova issue tracker]: https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Splashscreen%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC