UNPKG

10.5 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 is required to work with splash screens. This 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## Example Configuration
48In the top-level `config.xml` file (not the one in `platforms`), add configuration elements like those specified here.
49
50Please notice that the value of the "src" attribute is relative to the project directory and not to the www directory. You can name the source image whatever you like. The internal name in the app is determined by Cordova.
51
52```xml
53<platform name="android">
54 <!-- you can use any density that exists in the Android project -->
55 <splash src="res/screen/android/splash-land-hdpi.png" density="land-hdpi"/>
56 <splash src="res/screen/android/splash-land-ldpi.png" density="land-ldpi"/>
57 <splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>
58 <splash src="res/screen/android/splash-land-xhdpi.png" density="land-xhdpi"/>
59
60 <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
61 <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
62 <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
63 <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
64</platform>
65
66<platform name="ios">
67 <!-- images are determined by width and height. The following are supported -->
68 <splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>
69 <splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>
70 <splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>
71 <splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
72 <splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>
73 <splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
74 <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
75 <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
76 <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
77 <splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>
78</platform>
79
80<platform name="windows">
81 <!-- images are determined by width and height. The following are supported -->
82 <splash src="res/screen/windows/splashscreen.png" width="620" height="300"/>
83 <splash src="res/screen/windows/splashscreenphone.png" width="1152" height="1920"/>
84</platform>
85
86<platform name="blackberry10">
87 <!-- Add a rim:splash element for each resolution and locale you wish -->
88 <!-- http://developer.blackberry.com/html5/documentation/rim_splash_element.html -->
89 <rim:splash src="res/screen/blackberry/splashscreen.png"/>
90</platform>
91
92<preference name="SplashScreenDelay" value="10000" />
93```
94
95## Preferences
96
97#### config.xml
98
99- __AutoHideSplashScreen__ (boolean, default to `true`). Indicates whether to hide splash screen automatically or not. Splash screen hidden after amount of time specified in the `SplashScreenDelay` preference.
100
101```xml
102 <preference name="AutoHideSplashScreen" value="true" />
103```
104
105- __SplashScreenDelay__ (number, default to 3000). Amount of time in milliseconds to wait before automatically hide splash screen.
106
107```xml
108 <preference name="SplashScreenDelay" value="3000" />
109```
110
111### Android Quirks
112
113In your `config.xml`, you need to add the following preferences:
114
115```xml
116<preference name="SplashScreenDelay" value="3000" />
117<preference name="SplashMaintainAspectRatio" value="true|false" />
118<preference name="SplashShowOnlyFirstTime" value="true|false" />
119```
120
121The first parameter represents how long the splashscreen will appear in milliseconds. It defaults to 3000 ms.
122
123"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.
124
125The plugin reloads splash drawable whenever orientation changes, so you can specify different drawables for portrait and landscape orientations.
126
127"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).
128
129### Browser Quirks
130
131You can use the following preferences in your `config.xml`:
132
133```xml
134<platform name="browser">
135 <preference name="SplashScreen" value="/images/browser/splashscreen.jpg" /> <!-- defaults to "/img/logo.png" -->
136 <preference name="SplashScreenDelay" value="3000" /> <!-- defaults to "3000" -->
137 <preference name="SplashScreenBackgroundColor" value="green" /> <!-- defaults to "#464646" -->
138 <preference name="ShowSplashScreen" value="false" /> <!-- defaults to "true" -->
139 <preference name="SplashScreenWidth" value="600" /> <!-- defaults to "170" -->
140 <preference name="SplashScreenHeight" value="300" /> <!-- defaults to "200" -->
141</platform>
142```
143
144__Note__: `SplashScreen` value should be absolute in order to work in a sub-page. The `SplashScreen` value is used only for the browser platform. The value will be ignored for other platforms.
145
146### Android and iOS Quirks
147
148- In iOS, the splashscreen images are called launch images. These images are mandatory on iOS.
149
150- `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to
151 prevent the splash screen from fading in and out when its display
152 state changes.
153
154```xml
155 <preference name="FadeSplashScreen" value="false"/>
156```
157
158- `FadeSplashScreenDuration` (float, defaults to `3000`): Specifies the
159 number of milliseconds for the splash screen fade effect to execute.
160
161```xml
162 <preference name="FadeSplashScreenDuration" value="3000"/>
163```
164
165Note 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. )
166
167_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`:
168
169- 00:00 - splashscreen is shown
170- 00:02 - fading has started
171- 00:03 - splashscreen is hidden
172
173Turning 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.
174
175_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:
176
177```javascript
178navigator.splashscreen.show();
179window.setTimeout(function () {
180 navigator.splashscreen.hide();
181}, splashDuration - fadeDuration);
182```
183
184- `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false`
185 to hide the splash-screen spinner.
186
187```xml
188 <preference name="ShowSplashScreenSpinner" value="false"/>
189```
190
191## Methods
192
193- splashscreen.show
194- splashscreen.hide
195
196## splashscreen.hide
197
198Dismiss the splash screen.
199
200```js
201navigator.splashscreen.hide();
202```
203
204
205### BlackBerry 10, WP8, iOS Quirk
206
207The `config.xml` file's `AutoHideSplashScreen` setting must be
208`false`. To delay hiding the splash screen for two seconds, add a
209timer such as the following in the `deviceready` event handler:
210
211```js
212setTimeout(function() {
213 navigator.splashscreen.hide();
214}, 2000);
215```
216
217## splashscreen.show
218
219Displays the splash screen.
220
221```js
222navigator.splashscreen.show();
223```
224
225Your application cannot call `navigator.splashscreen.show()` until the app has
226started and the `deviceready` event has fired. But since typically the splash
227screen is meant to be visible before your app has started, that would seem to
228defeat the purpose of the splash screen. Providing some configuration in
229`config.xml` will automatically `show` the splash screen immediately after your
230app launch and before it has fully started and received the `deviceready`
231event. For this reason, it is unlikely you need to call `navigator.splashscreen.show()` to make the splash
232screen visible for app startup.
233
234[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