cordova-plugin-splashscreen icon indicating copy to clipboard operation
cordova-plugin-splashscreen copied to clipboard

Splash Screen Spinner Position

Open washingtong33k opened this issue 5 years ago • 6 comments

Feature Request

Motivation Behind Feature

We can't change the position of the spinner in splash screen, so it will be always centered

Feature Description

Currently the plugin doesn't offer a setting to position the spinner in splash screen, something like <preference name="SplashScreenSpinnerPosition" value="top|center|bottom" /> would be helpful

Alternatives or Workarounds

I didn't find any workarounds yet

washingtong33k avatar Apr 16 '19 18:04 washingtong33k

plugins/cordova-plugin-splashscreen/src/

for android: centeredLayout.setGravity(Gravity.BOTTOM|Gravity.CENTER); and layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);

u can see more about gravity and relativelayout here:

https://developer.android.com/reference/android/view/Gravity.html https://developer.android.com/reference/android/widget/RelativeLayout.html

for ios: CDVSplashScreen.m: _activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2 + number);

only change this number for position at center.

sorry about english, its not my native.

pedrovitor074 avatar Apr 23 '19 12:04 pedrovitor074

something like <preference name="SplashScreenSpinnerPosition" value="top|center|bottom" /> would be helpful

Where would this position the spinner? Would center be the current default?

janpio avatar May 05 '19 17:05 janpio

something like <preference name="SplashScreenSpinnerPosition" value="top|center|bottom" /> would be helpful

Where would this position the spinner? Would center be the current default?

yeah, i think center its the best

pedrovitor074 avatar May 06 '19 12:05 pedrovitor074

@pedrovitor074 Thank you thank you, Gravity.BOTTOM|Gravity.CENTER been looking for that.

jamespsterling avatar Sep 14 '19 17:09 jamespsterling

Thanks @pedrovitor074.

You could just add a hook and set the position then:

(Attention: That's just super quick and dirty..)

config.xml:

<platform name="ios">
    <hook src="hooks/after_build/after_build_modify_ios_spinner_position_action.js" type="after_build" />
</platform>

after_build_modify_ios_spinner_position_action.js

#!/usr/bin/env node

module.exports = function (context) {
    console.log("Preparing iOS spinner position correction");
    const fs = context.requireCordovaModule('fs');
    const pathToProject = 'platforms/ios/YOUR_PROJECT_NAME/Plugins/cordova-plugin-splashscreen/CDVSplashScreen.m';
    const pathToCDVSplashScreenFile = `${context.opts.projectRoot}/${pathToProject}`;

    fs.access(pathToCDVSplashScreenFile, fs.F_OK, (err) => {
        if (err) {
            console.error(err);
            return;
        }

        const dataRead = fs.readFileSync(pathToCDVSplashScreenFile, 'utf8');
        const newData = dataRead.replace('_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2);', '_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2 + 50);');

        fs.writeFileSync(pathToCDVSplashScreenFile, newData, 'utf8');
        console.log("Done preparing iOS spinner position");
    });
};

Make sure you replace the YOUR_PROJECT_NAME. Would be much better if someone would create a pull request and having the positions just in the config.xml file. But right now this works for me

StefanRein avatar Sep 16 '19 11:09 StefanRein

Thanks @pedrovitor074.

You could just add a hook and set the position then:

(Attention: That's just super quick and dirty..)

config.xml:

<platform name="ios">
    <hook src="hooks/after_build/after_build_modify_ios_spinner_position_action.js" type="after_build" />
</platform>

after_build_modify_ios_spinner_position_action.js

#!/usr/bin/env node

module.exports = function (context) {
    console.log("Preparing iOS spinner position correction");
    const fs = context.requireCordovaModule('fs');
    const pathToProject = 'platforms/ios/YOUR_PROJECT_NAME/Plugins/cordova-plugin-splashscreen/CDVSplashScreen.m';
    const pathToCDVSplashScreenFile = `${context.opts.projectRoot}/${pathToProject}`;

    fs.access(pathToCDVSplashScreenFile, fs.F_OK, (err) => {
        if (err) {
            console.error(err);
            return;
        }

        const dataRead = fs.readFileSync(pathToCDVSplashScreenFile, 'utf8');
        const newData = dataRead.replace('_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2);', '_activityView.center = CGPointMake(parentView.bounds.size.width / 2, parentView.bounds.size.height / 2 + 50);');

        fs.writeFileSync(pathToCDVSplashScreenFile, newData, 'utf8');
        console.log("Done preparing iOS spinner position");
    });
};

Make sure you replace the YOUR_PROJECT_NAME. Would be much better if someone would create a pull request and having the positions just in the config.xml file. But right now this works for me

Do you have this for Android Platform? Thank you in advance

niczm25 avatar Nov 04 '19 02:11 niczm25

Closing since the plugin no longer has iOS nor android code and spinner is not supported on browser nor windows

jcesarmobile avatar Sep 28 '22 21:09 jcesarmobile