Can i create an app with react similar to angular 2? - angularjs

I've been thinking of creating an hybrid app. I worked with ionic before, but i don't have any clue about react.
What i exactly needed is 'code once run anywhere' approach. The angular 2 is doing great in that i can write code for web app, android , apple devices and even windows.
I want to know whether i can do this in React. Can I create an app with react which runs on both web and mobile app as platform independent.
Thanks in advance!

Angular 2 and React are great frameworks/library(for react) which can run almost anywhere. In fact lets first determine what we mean with anywhere.
Angular 2 can server that app on web and if you are using a responsive format can serve mobile devices as well really fast. On devices you can serve it with ionic but the catch here is that this will be served with webviews which is actually a small placement inside the app to show html content. This rendering is rubbish if you want to serve native experience to the user. If not, then great ! Also you can have windows phones as well.
React on the other hand is easy to go in to code fast. I recommend using redux (which might take a while to get used to). Also with responsive design can serve many web devices really fast. Now on the smartphones the experience is native. Yes exactly native ! So if you plan the application correctly and split the logic right you can serve from the same app both application web + mobile. For windows phones now there is a limitation.
For desktops you can use electron as well and have it all!
I guess for me you must consider what your target is (time, devices, experience) and then decide.
Have fun!

Related

Use flutter web widgets inside a react js app

I have this project where I have to code a website and ios and android apps.
I have to do this with a very limited team (basically myself). So I want to share as much code between those platforms, to avoid maintaining different codebases as much as possible.
I have come to consider flutter : the logic (and interaction with the backend) in dart can be compiled to both ios and android, and to javascript for the web site to call. I also like how the UI is built using flutter.
For the web site, I know there is flutter web that can be used to do a web app, but I want my website to feel like a web site more than a single page app. I have thought about using React+Gatsby to do the website's ui, while calling the dart compiled js for the logic. That would enable high page loading speed, good seo, while keeping the interactivity of a react app and the single codebase logic through dart to js compilation.
I am wondering if this seems like a good approach to you, and if not, how you would do it.
In this approach, I am wondering if it would be possible to embedded flutter web widgets inside of react js components, always in a concern of maintaining as low platform specific code as possible. I have not found any other way of doing this than embedding them into iframes, which does not seem like a good idea, or does it ?
Update
Flutter Web is now available in a stable version for production.
Below answer is relevant back to the time when question was asked.
Flutter Web not recommended
At the current date, I would recommend not to use Flutter Web for production as it's in Beta. The Flutter Team is still working on improving quality, performance and browser compatibility. You must be cautious about using it as you may run into bugs and some other complications.
Also, I believe that the community support for Flutter Web might be on a lower side as it's pretty new.
Limited browser support
Another factor which bugs me is that the Flutter web apps can run on limited browsers as of now which would affect the reach to your user base:
Chrome (mobile & desktop)
Safari (mobile & desktop)
Edge (mobile & desktop)
Firefox (desktop)
What would I prefer?
Well, although it might be a hassle to handle different codebases for mobile and web platforms, I would still prefer to stick with React JS as it's much stable with better browser & community support as opposed to Flutter Web.
Good luck with your app! :)
I am unaware of how to use Flutter widgets inside a React app. But to address your other concerns,
So I want to share as much code between those platforms, to avoid maintaining different codebases as much as possible.
Given no other restrictions, this leads to a single Flutter app for both web and native. For a team as small as three we still found it easier than having multiple projects.
The key factor in merging our initial projects to one was the notion of mobile browsers. In a mobile browser you website should reduce itself to the look of your mobile app, unless they have different purposes. And this automatically happens with Flutter projects if you derive your layout breakpoints from screen size. Otherwise you would code your same narrow design twice: in Flutter for native apps and in React for web.
Same goes for native apps for tablets in landscape mode. They call for a layout that resembles your desktop browser version, and you automatically get it with Flutter.
Also in web version you may have more tools than in a native app, just because your screen allows it. Naturally, you would code this logic in JS. But then you get an order to migrate this to native apps. Would you then replace your JS logic with Dart logic compiled to JS and embedded into frames? This is a messy road.
Lastly, think of Mac, Linux and Windows platforms that will come to Flutter soon. Should you ever need a desktop native app, you would want the same layout as with web.
I want my website to feel like a web site more than a single page app.
The difference in feeling between a website and a single page app lies mostly in state management and URL handling. You may do the following to reduce it:
Introduce URLs for your pages. By default, in Flutter every piece of action can happen under a single URL of example.com/#/. The window then feels fragile as there is no URL to copy and get back to. Flutter's Router API, released in Oct 2020, allows you to generate URLs on any change in your app's state and parse the state back from URL. If you do it right, then everything on your screen becomes a function of the URL, just like in traditional websites.
Use url_stragegy package for your URLs to be example.com/path rather than example.com/#/path which immediately feels fake.
I have not found any other way of doing this than embedding them into iframes, which does not seem like a good idea, or does it ?
No, it does not. Mostly because you get too narrow a channel of communication of messages between JS windows. How would you listen to Flutter's BLoC's stream in another frame? It would take too much boilerplate code. Also I cannot think of easy debugging process.
To me, Flutter Web still has drawbacks:
It takes awhile to load.
Many specific JS APIs are not implemented yet.
Many services you integrate with may not have Dart SDK, while having JS SDK. For instance, I struggled to get Ably working.
No search engine optimization.
You cannot use em as a screen unit, so scaling elements may get tricky.
Still with limited resources a single codebase outweights everything else.
To be clear, my team has been working on a web+native project the whole 2021. It now has passed most of the testing, but not yet released. For a sense of scale, it is a marketplace of 40+ screens.

Can I create a mobile app wrapper around a web app using React Native, similar to what Cordova does to create mobile apps?

This is a high-level question and I'm looking for directional guidance before I dive deeper.
I have a web app written in react. My next step is to develop a mobile app across iOS/Android, and my original plan was to learn React Native and rewrite my app. However, learning RN will take time, and re-writing the app in RN completely will definitely take significant amount of time and effort.
My plan is to do so eventually, but my priority is speed over quality for now, and I was wondering if there is a much faster way to ship. So, is there a way to create a mobile app wrapper around my entire web app, similar to what Cordova does?
I am wondering if something like creating tag wrapper in App.js and then load my web app inside it using web view. (New to programming. Don't be too harsh. :)) Any advice will be welcome. Thanks!
Yes, you can use : react-native-webview or react-native-htmlview, depend on what you need.
But rumors says it will be block by app stores if there was web-views which using for SEO faking requests and etc, i don't know.

react.js desktop and mobile web project architecture

I have really big concern on my web project architecture which will have separate mobile and desktop web app.
I already finished to develop web version based on "create-react-app" project template and for mobile version, I want to reuse my exists web version component as much as possible.
We will serve these with separate url "www" for desktop and "m" for mobile.
I am thinking of two possible ways.
Just build another create-react-app project for mobile and share the common code.
In exists web client create-react-app project src folder, make mobile version codes like component.js component.web.js component.mobile.js. But in this case I am worrying about the size of bundle js file.
I also thought about the responsive web design, but we have totally different layout and components.
Rendering two different layout within a component by the size of viewport or url(www/m) might be another possible way but it is highly possible for me to use server-side-rendering...
What would be the good approach to solve this problem....
I would approach this as follows:-
Move all business logic to a common package and use it in both mobile and web. This would make your logic common.
Move all the common components/config/colors etc. to a common package and use them in both the apps.
Handle view part for both the apps separately.
I also thought about the responsive web design, but we have totally
different layout and components.
If you have totally different layout and components I would suggest to keep mobile and web segregated. Its not only about the bundle size, you can get around it by lazy loading, but your code complexity can increase.
You can use the same code and build mobile application using Cordova Framework
as your web code will be the one to generate application.
As well you can create for multiple platforms.
Go through official website.
https://cordova.apache.org/docs/en/latest/guide/cli/index.html

Is it possible to convert a webapp coded using angular 1 to PWA(Progressive Web App)?

I have a webapp devoloped using angular 1. I have to convert it to progressive web app is this possible, I had looked into many tutorials in youtube but all of them uses angular 2 and above. Does angular 1 supports this PWA features? Please help...
There's nothing framework-specific about PWAs - your site just has to meet a certain set of criteria:
Everything is served over HTTPS
The design must be responsive
Your app must be available offline (i.e. it needs a Service Worker)
You need to provide a manifest file containing metadata about your application
Your app must work in all modern browsers
Page transitions shouldn't block the app (i.e. you need to show loading screens/spinners if things are taking a while to load)
Each page in the app needs a unique URL
All of that is achievable with Angular 1 - it'll probably be easier with a modern framework, but there's nothing stopping you sticking with what you've got, for now at least.
Addy Osmani (who I believe works at Google and is pretty heavily involved with the PWA spec) has a good example of an Angular 1 PWA on his GitHub.
My code was successful, I had added serviceworker.js and manifest, I forgot to clear the caches in my mobile. That was the problem and not with the code. Now its working fine. Clear the caches in test devices and it to homescreen once again and it will work.

Cross platform mobile app / server architecture

I work on a team that supports a mobile web site. It's a typical web app in that it's pages of forms that submit and retrieve data from a server. Back end currently JSF.
It's working fine but there's a strong want to start leveraging more of the native device's components and features (namely messaging/alerts and UI widgets). Given the number of platforms we're trying to support (iOS, Android, BlackBerry, Symbian [yuck] and potentially Windows 7) PhoneGap seems to be the first thing I should spend some time looking at.
I think I have a good grasp on how it works (broadly speaking) in that it allows you to use HTML CSS and JS then builds a native app that 'wraps' around your code and offers up a JS API into the device's native widgets and features as needed.
What I'm not so clear on is how one would use it in a client/server type of interaction. Could we use PhoneGap to create a front end UI that would still talk live to our servers? If so, could we leverage standard AJAX/JSON/XML type technologies to send and receive the data or are there hidden hurdles I'm not aware of in doing that with a solution like PhoneGap? In otherwords, does the webview within the PhoneGap app work just as WebKit would in that we can make an AJAX call, get some data, and update the DOM?
Or is there a different type of framework I should be looking at?
A example summary explanation of what we're looking for would be: We'd like our current web application to be able to launch a native date picker on the device and receive alerts but still interact with our servers as our current mobile web site does.
As user731077 says, yes, PhoneGap can do all of that. There's a number of potential methods you could use to do so in the Javascript code of your PhoneGap app. Here's a few to check out.
XMLHttpRequest object, but I'd suggest one of the below choices that handles cross browser inconsistencies
jQuery ajax()
xui.js xhr() (my choice)
zepto.js ajax()
xui.js and zepto.js are my suggestions as they are basically stripped down versions of jQuery optimized for mobile web development. I'm partial to xui.js because its the framework commonly used by the PhoneGap guys themselves.
your every question has a YES answer :)

Resources