Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucabertolasi/3f15a848e8442f2dbc7fef749acbaaf0 to your computer and use it in GitHub Desktop.
Save lucabertolasi/3f15a848e8442f2dbc7fef749acbaaf0 to your computer and use it in GitHub Desktop.
[JavaScript] [Cordova] [cordova-plugin-splashscreen] Move splashscreen spinner position to bottom (iOS/Android).
#!/usr/bin/env node
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
// REQUIRES: https://github.com/apache/cordova-plugin-splashscreen
(() => {
const colors = require('colors')
const fs = require('bluebird').promisifyAll(require('fs'))
const APP_NAME = process.argv[2]
const PLATFORMS = [{
NAME: 'Android',
FILE: './platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java',
REPLACE: [{
from: 'centeredLayout.setGravity(Gravity.CENTER)',
to: 'centeredLayout.setGravity(Gravity.CENTER_HORIZONTAL)'
}, {
from: 'layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE)',
to: 'layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE)'
}],
DONE: false,
ERROR: false
}, {
NAME: 'iOS',
FILE: `./platforms/ios/${APP_NAME}/Plugins/cordova-plugin-splashscreen/CDVSplashScreen.m`,
REPLACE: [{
from: '_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2)',
to: '_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height - 25)'
}, {
from: 'UIActivityIndicatorViewStyle topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray',
to: 'UIActivityIndicatorViewStyle topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhiteLarge'
}],
DONE: false,
ERROR: false
}]
console.log('\niOS/Android -> moving splashcreen spinner from center to bottom...\n')
PLATFORMS.forEach(PLATFORM => {
fs.readFileAsync(PLATFORM.FILE, 'utf8')
.then(str => {
console.log(`${PLATFORM.NAME} -> read: ${PLATFORM.FILE}`.yellow)
PLATFORM.REPLACE.forEach(line => str = str.replace(line.from, line.to))
return fs.writeFileAsync(PLATFORM.FILE, str, 'utf8')
})
.then(() => {
PLATFORM.DONE = true
console.log(`${PLATFORM.NAME} -> write: ${PLATFORM.FILE}`.yellow)
console.log(`${PLATFORM.NAME} -> splashscreen spinner position: BOTTOM\n`.green)
})
.catch(e => {
PLATFORM.DONE = true
console.log(`${PLATFORM.NAME} -> error: ${e.stack}`.red)
console.log(`${PLATFORM.NAME} -> splashscreen spinner position: CENTER\n`.red)
})
.finally(() => {
if (PLATFORMS.map(PLATFORM => PLATFORM.DONE).every(done => done === true)) {
console.log('...done.\n')
PLATFORMS.map(PLATFORM => PLATFORM.ERROR).some(error => error === true)
? process.exit(1)
: process.exit(0)
}
})
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment