Web development & API design
L05: Elsewhere! Universal Web Apps, Progressive Web Apps, React Native
Assignment 1
- Will be possible to hand in via It's Learning later today
- (Sorry, creating them takes forever)
- /Assignments/A01: Hello, world!/Draft for feedback

Elsewhere!
Universal Web Apps

Universal Web Apps 101
- Code is shared between client and server
- Both client and server can render all pages (HTML)
- First request is loaded as HTML from the server
- Subsequent pages are rendered client-side
Pros
- Faster first render
- No "skipping" as things eventually load
- Works on all devices!
- … no need for JS!
- … no need for JS!
- Better Search Engine Optimisation (SEO)
Tradeoffs
- Much more complex server
- Node lock-in
- react-dom/server isn't great; FB doesn't use it
- Requires Babel for JSX
UWA
Server-side rendering w/React
const React = require('react');
const ReactDOMServer = require('react-dom/server');
class MyComponent extends React.Component {
render() {
return <div>Hello World</div>;
}
}
const html = ReactDOMServer.renderToString(
<MyComponent />
);

Progressive Web Apps!
Progressive Web Apps 101
- Progressive enhancement (use features if they're available)
- Backed by Service Workers
- Offline support with storage like IndexedDB
- Push notifications
- Background data sync
- Geofencing (in the future)
- Act like native apps
- Add to home screen
- Share via URL (no need for app store)
Why aren't we seeing tons of PWAs?


There is hope!

React Native!
React compiled for apps!
- Build an app with familiar React code!
- Android + iOS
- Components compile to native widgets, not WebView
- Great developer tools with Hot Reloading
Native bridge
- Develop stuff natively if you need to
- Android SDK (Java)
- Objective-C/Swift (iOS)
- Bridge it together with JS
- We're going to just use JS
Separate code for iOS & Android
-
(If you want it)
- file-name.ios.js | file-name.android.js
- Useful for native components
- Design guides differ!
Style a component!
Flexbox
DEMO: Hello RN!
Holy crap this works in
the browser too!

Elsewhere!
Øving!
- $ yarn global add react-native-cli
- $ react-native init HelloReactNative
- $ cd HelloReactNative
- If
- Windows/Linux
- $ react-native run-android
- Depends on Android SDK
- macOS
- $ react-native run-ios
- Depends on XCode
- Windows/Linux
- Get things running
- Start Node server from previous exercise
- Download data using fetch in the React Native app!
PG6300-17-05: React Elsewhere! React Everywhere!
By theneva
PG6300-17-05: React Elsewhere! React Everywhere!
- 511