I'm looking at NativeScript and I see a lot of potential for making app development easier. The question that I have right now is whether or now it's possible to run NativeScript on the fly. For example, is it possible to create an iOS app fully written in Objective-C and then leave an about page to NativeScript and get the script from a source in runtime and evaluate it in the app, the way JavaScript gets evaluated for each web page?
I read that NativeScript does use JIT but what I don't understand the require mechanism, how is it possible to require Node modules if you evaluate code in runtime.
React Native lets you do this. I'm not endorsing it as I'm evaluating solutions as well, but technically you can instantiate their bridge and manage it from existing iOS apps, they even have example repos.
Yep, to some extent. Their is no easy mechanism in NativeScript to let you start your ObjC app; and then call into NativeScript. You can do it the opposite; start a NativeScript application and call into your own ObjC. NativeScript is the controller of the application.
As for dynamic pages; yes this is very easy to do. In fact I use a technique to do just this in my NativeScript-LiveSync plugin. All the JavaScript is evaluated at runtime.
Related
Is there a way to compile Node.js code to regular JavaScript?
I've wanted to use Node.js code for my web application for a while.
I've tried to use Express, but there was no way I could make it work without converting the HTML file to EJS.
I know it is possible because of the way Create React App builds, but I don't know how to achieve that.
Any solution would help, and it would also help me if you could answer some of these questions
(these are some that I tried and gave up on):
Is there a way to access the document variable with express (keep in mind that I'm working with a framework that requires to have access to the document variable)?
Is there any way I could just import modules to my JavaScript file (basically using require() without node)?
Is there any way I could ship the part of Node.js that I actually need togeher with my application (and yes, it is in fact the require() function)?
You are mixing up a lot of concepts and I would strongly suggest reading more about JavaScript and the difference between executing it on the frontend (web browsers) and the backend (NodeJS)...
Here are a few (quick) answers to some of your questions:
Code that runs in NodeJS is regular JavaScript. However if you use NodeJS APIs, it will not run in a web browser, which has a different execution environment runtime.
The document object only exists in a web browser environment, it has no meaning in a NodeJS environment which is a backend.
require is a NodeJS API to load CommonJS packages, it does not exist in a web browser environment. There are alternatives like RequireJS or Browserify, or you can use import for ES modules (with proper CORS details set up).
Express is a server-side routing library, it is not meant to run in web browser environment.
If you are trying to build a web application, you could start by looking into JS frameworks that do the heavy lifting for you like Svelte, Angular, React, Vue (to name only the most popular ones).
We have a large ecosystem of Javascript websites, actually Angular, that we don't plan to rewrite in c# any time soon. So the goal here is to be able to use a vendor dll in our javascript to add new features. This is a proprietary system, we don't have any alternative, either we use their dll, either we don't have the feature. I'm putting a lot of hope in webassembly here because this looked like the silver bullet to use that dll without having to rewrite the whole project in a new language.
Problem: all the examples I can find are more about using Blazor to write a website or call javascript from Blazor, I can't find anything to include some ad-hoc C# code into an existing project. I would have thought it would be a great use case though because being able to leverage C# threadpool on a webpage sounds pretty good to me!
Anyone has done something similar or know some examples/tutorials I could follow?
As Tuan says Angular and C# don't really live together in the way you suggest.
I would say there are 2 separate approaches here.
Have an C#.NET MVC app but adjust the routing so the Angular App Handles some pages and the .NET app handles others. This is OK but there are so many pitfalls such as the fact that you can not share bundled CSS and JS or maintain the structure of your Angular controllers (amongst others).
A better way would be keep your lovely Angular app the way it is but have a separate Web API application/project and use the angular app to call the dll (reference in the project) within the correct context as a REST API (via a simple POST or GET call).
It's not too clear exactly what you want to do when you say "... able to use a vendor dll in our javascript to add new features ..." but you can find info on writing and implementing C# as a Web API in .NET core here
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio
I'm trying to create an Android App but I'm not too familiar with Java. I was thinking to use a hidden WebView to store my core code (as Javascript) there and call out functions between WebView's Javascript and app's Java code. Is this a bad practice? I know that I can use frameworks like Cordova, PhoneGap but they are all bloated with code that I will never use.
3 Reasons to Prefer React Native,
1- You are good at JavaScript (you told that you are not too
familiar with Java)
React Native is Really Native
JSX and
React Component Props (eg. flex styles almost same with CSS) are
close to JavaScript Developers
WebView is not the best practice ;)
Good Luck
I am trying to create a iOS/Android app based on a client side html5 web project, (i.e. a site) I did.
I thought Ionic would be the ideal choice, that it would help me to port my web application as soon as possible.
In my site, I would use the 'script src="https:// ..."' tag to load the external lib, then calling it in another script
tag. However, I can't import and use it in Ionic3.
I tried many solutions tagged with 'ionic2' and nothing really seems to work.
It also seems no one knows a general solution for this, since each answer was case-specific.
Does anyone know a general way of importing external js file and using its objects and 'classes' in ionic3?
(I would prefer to load from the web, but I am also accepting to download and load it fro file. )
(If ionic isn't the best way of accomplishing my objective, I am open to suggestions)
I think you need to wait till release the Ionic 4 and Stencil.
What is all about Ionic 4 and Stencil?
The magical, reusable web component generator.
Stencil is a tool for building modern Web Components
Stencil combines some of the best features from traditional
frameworks, but outputs 100% standards-compliant Custom Elements, part
of the Web Component spec.
Stencil was created by the Ionic Framework team to build faster, more
powerful mobile and web apps. Stencil is the foundation for the next
generation of Ionic Framework, but is completely independent of Ionic
or any other UI framework.
Here you can see the official doc.
Nice video about the power of Ionic 4
Nice article about it
First of all have a look at this useful ionic resource, it explains how to add thirs party libraries using npm.
If you cannot use npm because of whatever reason you have to put the source .js file into your assets/js folder and import it in your index.html using a <script> tag. Then you have to tell typescript that your library exists. This is done like so: declar var <library-handle>. Where <library-handle> can be an exported function/class if the library already uses ES2015 or the object which exposes the functions using prototype. This is the tricky part where you may have to try a few things until you get it to work.
You can have a look at my answers here, here and here where I explained how to add different third party libraries to ionic projects.
I need to create an internal admin app. The app needs to be able to:
For V1
- Wrap and execute javascript code
- Will not rely on any iOS code other than perhaps the code necessary to load the javascript.
- Uses local storage
For V2
- Work offline (which means javascript code needs to be loaded in)
Any ideas on how to go about implementing such a thing?
By far the easiest and best supported way is to use Apache Cordova. They did all the work of wrapping a Webview in a native app and have a rich set of plugins for integration with all kinds of mobile APIs.
Since the app will be running in an embedded browser you can simply access the normal Localstorage APIs.
The Cordova tutorial by #ccoenraets may be a good way to get started.
From my findings the following two are great solutions:
Ionic
Apache Cordova