Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No hooks for Platform specific UI #58

Open
mix3d opened this issue Jul 25, 2017 · 3 comments
Open

No hooks for Platform specific UI #58

mix3d opened this issue Jul 25, 2017 · 3 comments
Labels

Comments

@mix3d
Copy link

mix3d commented Jul 25, 2017

I found the build script to be a bit lacking; there's no support for building the Material UI for android builds and Apple design for iOS builds.

Here's what worked for me, but I doubt it's a "best practices" approach.


Split main.js into a main.ios.js and main.android.js. The latter has the suggested material:true and correct CSS uncommented and iOS removed. All your Vue components should handle multi-platform builds already. (using v-if="$theme.material" where needed, etc)

hookers.js
add to sys object a new function to check if a certain platform is being run.
Note: If building both iOS and Android in one command, (cordova build ios android), platforms will have both values. For this function, it only checks if the specified platform is a part of the command, not if it is the only platform.

checkPlatform(name) {
	return (
		typeof ctx.opts !== 'undefined' &&
		typeof ctx.opts.platforms !== 'undefined' &&
		(
			Array.isArray(ctx.opts.platforms) &&
			ctx.opts.platforms.indexOf(name) > -1 ||
			ctx.opts.platforms[name] === true
		)

	)
},

and change the startWebpackBuild function to take an isAndroid parameter, and use it for the exec command. (Webpack 2.0 requires passed args through the --env. prefix)

startWebpackBuild(isRelease, isAndroid) {
	...
	 exec(`"${wpPath}"` + (isRelease ? ' --env.release' : '') + (isAndroid ? ' --env.android':' --env.ios'), {cwd: pRoot, maxBuffer: 1024 * 1024 * 5}, 
	...
}

then, using isAndroid = sys.checkPlatform('android'), you update the call with our new value sys.startWebpackBuild(isRelease, isAndroid))

Now that webpack knows which platform it is building for, move the definition of the entryFile variable inside the config function, and update as follows:

webpack.config.js

let config = function (env) {
    let entryFile = path.join(__dirname, env.android ? 'src/main.android.js' : 'src/main.ios.js')
    ....

Now you are building the platform correctly!

Background: I tried to do conditional imports inside the main.js (and therefore bypass all this by setting the needed values on runtime), but was unable to get a webpack / component-ey version working. This approach works for my needs, and hopefully can help someone else trying to have one codebase for platform agnostic native UI, (even if its a little contrived to get the variables into webpack and ultimately the F7+Vue App)

@caiobiodere
Copy link
Owner

@mix3d are you still looking for this solution or did you find anything else?

@mix3d
Copy link
Author

mix3d commented Jul 16, 2018

The solution I posted worked for me, and I moved on. I would still love to see a better approach, however, but this was also f7 1.x and not 2.x

@caiobiodere
Copy link
Owner

@mix3d I will work through your way if I find anything else I will tell you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants