Is there a way to convert cocos2d-x project working on iOS and Android to convert it to html without converting the code to JS? - cross-platform

I have completed a project which is completed on iOS and Android with all native code like in-app purchases and leaderboard completed. I want to convert that project into HTML 5 but without changing my C++ code to javascript and using the same resources. Is there any method/way to convert my code?
I was a native obj-c programmer who joined cocos2d-x porting from cocos2d-iphone. I have little/no knowledge of html or javascript.

If you want the resulting app to run within the browser, then no. There's no cocos2d variant that makes this possible. You would have to port the app to a completely different (but still C++) framework. See: How to build native C++ apps with HTML/CSS UI?
You can of course build a c++ app with cocos2d-x that presents a html5 view, but it won't run within the browser.

Related

React Native compiling for Android -Beginner

I am a newbie to react native.
1.) I need to know if I can create a react native application and import it to Xcode, then add code in swift?
2.) I also need to know if the components I developed with swift can be compiled and run as a Android application?
Yes you can definitely do this, it's pretty common.
No, that swift code will not run on android
To help understand this, all UI code written in React Native is translated into corresponding native languages, everything else stays as Javascript.
Your Swift code cannot be translated back into Javascript that can then run on Android and certainly cannot be translated into Java.

What is meant by Flutter's widgets aren't really adaptive

I have been trying my hands for POC on an idea and trying to find languages which can support Mobile app development (Android/IOS) via single source code.
I zeroed on React-Native and Flutter.
What I found that for React-Native you still have to write code which is platform specific. Components need to be written differently for IOS and Android.
Then I looked in FLutter and I found that - "Flutter's widgets, however, while there are more of them, aren't really adaptive".
I am not able to understand it and what it means.
It would be really helpful if someone can help me with example or guide me to good reference.
In Flutter you have different sets of Widget Collection:
Material Widgets: Android-style
Cupertino Widgets: iOS-style
And lots of Widgets which aren't bound to one of those styles.
With this you are able to create a application looking like any style on any of the available platform. Therefore you can also have iOS-style Widgets on Android and vice versa.
If you want to have iOS Widgets on iOS and Android Widgets on Android, you'll have to create some conditional rendering, which decides wether to render iOS or Android components.
Sidenote: The Material-style Widgets look also really good on iOS. Also you can use a ton of other Widgets to create an UI in your own style.

Different UI for Android/iOS in interpreted JS cross-platform tools

Some cross-platform tools (like Xamarin native and RubyMotion) allow the development of two separate views for Android and iOS, while keeping the business logic shared for both of them. Others (like Apache Cordova or Xamarin.Forms) share both UI and business layer, with the option to use platform-specific overrides when necessary.
What is the state of the interpreted JavaScript frameworks (NativeScript, React Native or Appcelerator)? Are they all focused on creating single UI with platform overrides, or do they allow creating two separate views for each platform? For example, is it possible to create a view using Fragments in Android, but a different view on iOS (since Fragments do not exist there)?
Cordova uses WebView, that mean GUI level will be the same for both Android and iOS but different per Device version. In case of Android each client has own Chronium version and it can break UI behaviour. So developers use Crosswalk to set fixed Chronium version. (extra 20M to your application).
BTW Ionic that uses Cordova architecture uses native behaviour per platform. For example for Android Tabs located at the top, on iOS - at the bottom
On other hand Xamarin (C#), React-Native(JS) and NativeScript(JS) call native APIs. They don't use WebView but generate Native code.
For example if you create button - it will look different: on Android - material theme, on iOS - iPhone theme
Anyways, the bottom line is: everything depends on resources and time. If you want to build application fast, with the same view - I would go on Ionic2+ Angular2 + Cordova.
If you you have more time - go on React-Native or NativeScript (Still has poor documentation) or Xamarin (C#).
React-native's slogan is Learn once, write everywhere. So, you can choose what suits your needs, you can:
Share UI between platforms.
Share Only business logic.
So, the answer for react-native is yes. You can create separate UIs or you can share it.
Since you are writing components, one way of separating this logic is to write component.android.js and component.ios.js and the platform loads the appropriate one for you. Note that you can also do that programmatically.
You can see that in action in the official f8 app made by facebook using react-native

How react native works? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Can someone explain how react native works?
Found a lot of good articles about getting started, components usage, exporting modules.. but,
Googling about how react native works doesn't really help, but this article http://tadeuzagallo.com/blog/react-native-bridge that explains how native modules are exported and what happens when javascript calls them.
.. Still I find it difficult to understand (as a javascript dev) things like,
how first render happens on the screen, what are the functions of those 3 threads and how they communicate with each other, what is this javascript event loop, why do we need batched calls and how it is batched, etc..,
Can someone share an article/explain it in a javascript developer perspective?
thanks!
I will try to describe how React Native works. It's a bit complicated.
And first of all I will like to recommend this URL to learn about basics internal mechanism of React Native:
Read: https://www.reactnative.guide/3-react-native-internals/3.1-react-native-internals.html
So you are writing code in JS/JSX (JavaScript) or TS/TSX (TypeScript) but Android uses primarily Java (for sake of this answer, we know it's Kotlin now) and iOS use Swift/Objective-C so how the java script code is running in your Java Virtual Machine or Dalvik Virtual Machine or whatever iOS use.
So here is the problem how to run JavaScript code in Android Machine (iOS machine),
1) Use WebView, but WebView is slow, there is a lot going on in a WebView, so much heavy lifting is done for you by the Android/IOS Machine to run Web Pages in your application. Page loads slowly, scrolling jerks and what not. That's why Cordova and PhoneGap apps don't work well.
2) We don't need WebView right, we need light-weight JavaScript compiler(interpreters) which can compile only a set of JS instructions not all of them. A program which targets only core JavaScript and read new defined XML/ReactNative tags. React-Native tags (Image, FlatList, Text etc) are converted on JS side and converted to JS methods calls not on Android/IOS side.
Read: https://reactjs.org/docs/react-without-jsx.html
JSX is first converted to JS first.
3) Here, JavaScript-Virtual Machine comes into play which is completely different from JVM or DVM. And can run on JVM or DVM.
React Native uses : JavaScriptCore
Read: https://www.raywenderlich.com/1227-javascriptcore-tutorial-for-ios-getting-started (This is for IOS)
Here is one and open source for you to look around
https://github.com/LiquidPlayer/LiquidCore: This is even contains a file system, react-native does not.
Note: Same idea FB used for NodeJs = backend JavaScript.
4) JS-Bundle: So now you can run JS code in your application, but how do you ship it. You will create one file i.e merge of the all the files and library files into one and call it JS-Bundle.
Simple command for Android
node node_modules/react-native/local-cli/cli.js bundle --entry-file index.js --platform android --bundle-output ../jsbundle/index.android.jsbundle --assets-dest ../jsbundle/res
5) JS-Bridge: Like the name provides bridge methods and components to communicate JavaScript and Native-Code(Android Java). How do they communicate, like everything else in React-Native, using JSON. JSON commands are sent to UiManager in native code to create UI on an asynchronous thread, which adds these commands into MessageQueue and process them.
Read: https://hackernoon.com/understanding-react-native-bridge-concept-e9526066ddb8
Also Read : https://tadeuzagallo.com/blog/react-native-bridge/
6) Threads:
JS-Thread : Handles UI commands as explained earlier. JS thread is
created as soon you invoke React-Native view from Android Code (Starting React Activity) and handles every view create or change command from React Native.
Native-Thread(Main Thread): Take press or touch events and pass them to JS-VM,
JS-VM passes them to your code, if success , process them and View change events are passed to your JS-Thread.
Async-Threads Now I don't have much idea about how do you create threads inside your JS/JSX code. Maybe it's possible but before it was not.
So for a JS point view your writing JS code that will run on light weight browser that is ReactView.
Read: https://www.codementor.io/#saketkumar95/how-react-native-works-mhjo4k6f3

Download and display PDF with Trigger.io and jQuery Mobile

We are going to develop a mobile app (iOS and Android), which should provide downloading and storing several user-selected PDF files and viewing them within the app (iOS with WebView) or with an external PDF Viewer (Android).
My Question is: Is this possible with Trigger.io? I didn't find anything concerning this in the official documentation. Can we do something with the file or the child browser / tabs module? If yes, do you have any examples?
Note: We will use Backbone.js and jQuery Mobile as additional libraries.
The Android webview doesn't allow for inline opening of PDFs - you can test that by opening e.g. http://trigger.io/cross-platform-application-development-blog/wp-content/uploads/2012/05/trigger.io-whitepaper.pdf in your stock browser.
On iOS, you can use:
forge.tools.getURL('my_file.pdf',
function (file) {
forge.tabs.open(file);
}
);
But that won't work on Android (tested on 2.3, 3 and 4.0).
Short answer - yes.
Downloading, storing, then showing/referencing later can definitely be done. Check out the forge.file documentation.
I have not tried the child browser feature yet. Although the tabs module will work, I think its best to just let the device (and its user settings) decide how to display/render the PDF. I am only saying this because my devices (especially the Android ones... 2.3 and 4.x) tend to behave differently. Either way... the device's "back button" always gets me back to where I left off in my trigger.io app.