Skip to content

Commit 78460a1

Browse files
committed
Initial version of the plugin
1 parent c00471a commit 78460a1

10 files changed

+304
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
npm-debug.log

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## 1.0
4+
Initial Release

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
1+
[![npm](https://img.shields.io/npm/v/cordova-plugin-launchscreen-storyboard.svg?maxAge=86400)](https://www.npmjs.com/package/cordova-plugin-launchscreen-storyboard)
2+
[![npm](https://img.shields.io/npm/dm/cordova-plugin-launchscreen-storyboard.svg?maxAge=86400)](https://www.npmjs.com/package/cordova-plugin-launchscreen-storyboard)
3+
[![npm](https://img.shields.io/npm/l/cordova-plugin-launchscreen-storyboard.svg?maxAge=2592000)](https://www.npmjs.com/package/cordova-plugin-launchscreen-storyboard)
4+
15
# cordova-plugin-launchscreen-storyboard
26
A cordova plugin for using a launch screen storyboard as the splashscreen instead of an image
7+
8+
# Installation
9+
`cordova plugin add cordova-plugin-launchscreen-storyboard`
10+
11+
or via github
12+
13+
`cordova plugin add https://github.com/toddbluhm/cordova-plugin-launchscreen-storyboard.git`
14+
15+
16+
# Usage
17+
18+
Add the following code to your `config.xml` to get the plugin with default settings:
19+
```xml
20+
<plugin name="cordova-plugin-launchscreen-storyboard" spec="~1.0.0" />
21+
```
22+
23+
or to add it with all the settings use the following code:
24+
25+
```xml
26+
<feature name="LaunchScreen">
27+
<param name="ios-package" value="LaunchScreenStoryboard" onload="true" />
28+
<preference name="StoryboardName" value="LaunchScreen" />
29+
<preference name="FadeOut" value="true" />
30+
<preference name="FadeOutDuration" value="0.5" />
31+
</feature>
32+
```
33+
34+
Once the plugin is setup you must now tell it when to fade out. You can do this by setting up a handler in `index.html` for the [`deviceready`](http://cordova.apache.org/docs/en/6.x/cordova/events/events.html#deviceready) event.
35+
36+
Something like the following should work:
37+
```js
38+
document.addEventListener("deviceready", function() {
39+
window.LaunchScreen.hide();
40+
}, false);
41+
```
42+
43+
# Preferences
44+
- **`StoryboardName`** - The name of the storyboard that contains your launch screen view controller.
45+
This will only instantiate the top level view controller in the storyboard.
46+
47+
- **`FadeOut`** - Enable/Disable the view fading out when its told to `hide()`. This uses an EaseOut function.
48+
49+
- **`FadeOutDuration`** - How long should the fade out last (in seconds).
50+
51+
# API
52+
53+
These are the javascript APIs exposed off of the `window.LaunchScreen` object.
54+
55+
- **`hide( callback )`** - Hides the launch screen. Usually called in the `deviceready` event handler. The `callback` is called after the launch screen is fully hidden.
56+
57+
- **`show()`** - Shows the launch screen. Should never need to be called in practice.
58+
59+
# Supported Platforms
60+
- iOS

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "cordova-plugin-launchscreen-storyboard",
3+
"version": "1.0.0",
4+
"description": "Cordova LaunchScreen Storyboard Plugin",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/toddbluhm/cordova-plugin-launchscreen-storyboard"
8+
},
9+
"keywords": [
10+
"cordova",
11+
"launchscreen",
12+
"ecosystem:cordova",
13+
"cordova-ios",
14+
"storyboard",
15+
"splashscreen"
16+
],
17+
"scripts": {
18+
"test": "standard --fix"
19+
},
20+
"engines": {
21+
"cordovaDependencies": {
22+
"0.1.0": {
23+
"cordova": ">=3.0.0"
24+
},
25+
"3.0.0": {
26+
"cordova": ">100"
27+
}
28+
}
29+
},
30+
"author": "Todd Bluhm",
31+
"license": "MIT",
32+
"devDependencies": {
33+
"standard": "^8.5.0"
34+
},
35+
"cordova": {
36+
"id": "cordova-plugin-launchscreen-storyboard",
37+
"platforms": [
38+
"ios"
39+
]
40+
}
41+
}

plugin.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3+
id="cordova-plugin-launchscreen-storyboard"
4+
version="1.0.0">
5+
<name>LaunchScreenStoryboard</name>
6+
<description>Cordova LaunchScreen Storyboard Plugin</description>
7+
<license>MIT</license>
8+
<keywords>cordova,launchscreen,storyboard,ios</keywords>
9+
10+
<engines>
11+
<engine name="cordova" version=">=3.0.0" />
12+
</engines>
13+
14+
<js-module src="www/launchscreen.js" name="launchscreen">
15+
<clobbers target="window.LaunchScreen" />
16+
</js-module>
17+
18+
<platform name="ios">
19+
<config-file target="config.xml" parent="/*">
20+
<feature name="LaunchScreen">
21+
<param name="ios-package" value="LaunchScreenStoryboard" onload="true" />
22+
<preference name="StoryboardName" value="LaunchScreen" />
23+
<preference name="FadeOut" value="true" />
24+
<preference name="FadeOutDuration" value="0.5" />
25+
</feature>
26+
</config-file>
27+
28+
<header-file src="src/ios/LaunchScreenStoryboard.h" />
29+
<source-file src="src/ios/LaunchScreenStoryboard.m" />
30+
31+
</platform>
32+
</plugin>

src/ios/LaunchScreenStoryboard.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// LaunchScreenStoryboard.h
3+
//
4+
// Created by Todd Bluhm on 11/1/16.
5+
//
6+
7+
#ifndef LaunchScreenStoryboard_h
8+
#define LaunchScreenStoryboard_h
9+
10+
#import <Foundation/Foundation.h>
11+
#import <Cordova/CDVPlugin.h>
12+
13+
@interface LaunchScreenStoryboard : CDVPlugin {
14+
BOOL _visible;
15+
BOOL _destroyed;
16+
UIViewController* _launchScreenViewController;
17+
NSString* _storyboardName;
18+
BOOL _performFadeOut;
19+
float _fadeOutDuration;
20+
float _launchScreenStartAlpha;
21+
}
22+
23+
- (void)show:(CDVInvokedUrlCommand*)command;
24+
- (void)hide:(CDVInvokedUrlCommand*)command;
25+
26+
@end
27+
28+
#endif /* LaunchScreenStoryboard_h */

src/ios/LaunchScreenStoryboard.m

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// LaunchScreenStoryboard.m
3+
//
4+
// Created by Todd Bluhm on 11/1/16.
5+
//
6+
7+
#import "LaunchScreenStoryboard.h"
8+
#import <Cordova/CDVViewController.h>
9+
10+
#define kDefaultStoryboardName @"LaunchScreen"
11+
#define kDefaultFadeOut YES
12+
#define kDefaultFadeOutDuration 0.5f
13+
14+
@implementation LaunchScreenStoryboard
15+
16+
- (id)settingForKey:(NSString*)key
17+
{
18+
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
19+
}
20+
21+
- (void)pluginInitialize
22+
{
23+
// Get all the plugin settings
24+
_storyboardName = [self settingForKey:@"StoryboardName"];
25+
if (_storyboardName == nil) {
26+
_storyboardName = kDefaultStoryboardName;
27+
}
28+
29+
NSString* fadeOut = [self settingForKey:@"FadeOut"];
30+
if (fadeOut == nil) {
31+
_performFadeOut = YES;
32+
} else {
33+
_performFadeOut = [fadeOut boolValue];
34+
}
35+
36+
NSString* fadeOutDuration = [self settingForKey:@"FadeOutDuration"];
37+
if (fadeOutDuration == nil) {
38+
_fadeOutDuration = kDefaultFadeOutDuration;
39+
} else {
40+
_fadeOutDuration = [fadeOutDuration floatValue];
41+
}
42+
43+
UIStoryboard* sb = [UIStoryboard storyboardWithName:_storyboardName
44+
bundle:nil];
45+
_launchScreenViewController = [sb instantiateInitialViewController];
46+
_launchScreenStartAlpha = _launchScreenViewController.view.alpha;
47+
48+
[self show:nil];
49+
}
50+
51+
- (void)show:(CDVInvokedUrlCommand*)command
52+
{
53+
_launchScreenViewController.view.alpha = _launchScreenStartAlpha;
54+
[self.viewController addChildViewController:_launchScreenViewController];
55+
_launchScreenViewController.view.frame = self.viewController.view.frame;
56+
[self.viewController.view addSubview:_launchScreenViewController.view];
57+
[_launchScreenViewController didMoveToParentViewController:self.viewController];
58+
59+
[self returnSuccess: command];
60+
}
61+
62+
- (void)hide:(CDVInvokedUrlCommand*)command
63+
{
64+
if (_performFadeOut) {
65+
[UIView animateWithDuration:_fadeOutDuration
66+
delay:0
67+
options:UIViewAnimationOptionCurveEaseOut
68+
animations:^{
69+
_launchScreenViewController.view.alpha = 0.0;
70+
}
71+
completion:^(BOOL finished) {
72+
[self removeLaunchScreen];
73+
[self returnSuccess: command];
74+
}];
75+
} else {
76+
[self removeLaunchScreen];
77+
[self returnSuccess: command];
78+
}
79+
}
80+
81+
- (void)removeLaunchScreen
82+
{
83+
[_launchScreenViewController willMoveToParentViewController:nil];
84+
[_launchScreenViewController.view removeFromSuperview];
85+
[_launchScreenViewController removeFromParentViewController];
86+
}
87+
88+
- (void)returnSuccess:(CDVInvokedUrlCommand*)command
89+
{
90+
if (command != nil) {
91+
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
92+
callbackId:command.callbackId];
93+
}
94+
}
95+
96+
@end

tests/plugin.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3+
xmlns:rim="http://www.blackberry.com/ns/widgets"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
id="cordova-plugin-launchscreen-storyboard-tests"
6+
version="1.0.0">
7+
<name>Cordova LaunchScreen Storyboard Plugin Tests</name>
8+
<license>MIT</license>
9+
10+
<js-module src="tests.js" name="tests">
11+
</js-module>
12+
</plugin>

tests/tests.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-env jasmine */
2+
3+
exports.defineAutoTests = function () {
4+
describe('LaunchScreen', function () {
5+
it('launchscreen.spec.1 should exist', function () {
6+
expect(window.LaunchScreen).toBeDefined()
7+
})
8+
9+
it('launchscreen.spec.2 should have show|hide methods', function () {
10+
expect(window.LaunchScreen.show).toBeDefined()
11+
expect(typeof window.LaunchScreen.show).toBe('function')
12+
13+
expect(window.LaunchScreen.hide).toBeDefined()
14+
expect(typeof window.LaunchScreen.hide).toBe('function')
15+
})
16+
})
17+
}

www/launchscreen.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var exec = require('cordova/exec')
2+
3+
var LaunchScreen = {
4+
hide: function () {
5+
exec(null, null, 'LaunchScreen', 'hide', [])
6+
},
7+
8+
show: function () {
9+
exec(null, null, 'LaunchScreen', 'show', [])
10+
}
11+
}
12+
13+
module.exports = LaunchScreen

0 commit comments

Comments
 (0)