ãã£ã³ã¹ã¯ããªãã¯ãã®èŠãŠããŠããã®çš®é¡ã«ã€ããŠãã€ãã£ãã«åå¿ããã©ã®ããã«äŒæ¥ããããŠãããã£ãŒãããã¯ã移åããããšããé¢ããŠãäŒç€Ÿã§ã¯ãªããäžäººã®éçºè ããã®å人çãªæèŠãå ±æããŸãã
ãã®èšäºã¯ã次ã®ãããªæ¹ã察象ãšããŠããŸãã
- ã¯ãã¹ãã©ãããã©ãŒã ã«ç²ŸéããŠãããããã¯ãããžãŒéã®äž»ãªéããç解ããããšèããŠããŸãã
- 圌ã¯ReactNativeã§æžããŠããŠãFlutterã«åãæ¿ããããšã§äœãåŸããããç¥ããããšæã£ãŠããŸãã
- React Nativeã§èšè¿°ãããFlutterã§ã®ã¿èšè¿°ããŸããã
以äžã«ãç§ãReact Nativeãéžæããçç±ã説æããFlutterãé¢ããçç±ãå ±æããReactNativeãšFlutterã®äž»ãªéãã説æããŸããããã¯ç§ã®æèŠã§ã¯æãéèŠã§ããReact Nativeãé¢ããŠããããªãã®æéãçµéããŸãããäœããå€æŽãããä¿®æ£ãããŸãããç§ã¯ãããèæ ®ã«å ¥ããããšããŸããããäœããéããå¯èœæ§ããããŸãã
ReactNativeãéžãã çç±
2017幎ã«React.jsã䜿çšããWebéçºããReactNativeã«æ¥ãŸãããå瀟ã¯React / ReactNativeéçºè ãå¿ èŠãšããŠããŸããã
åå ïŒ
- åãèšèªã¯JavaScriptã§ãã
- UIãšã³ã³ããŒãã³ãã·ã¹ãã ãæ§ç¯ããããã®åãã«ãŒã«ã
- ã¯ãã¹ãã©ãããã©ãŒã ã
ãªããã©ãã¿ãŒã«åãã£ãã®ã
React Nativeã¯ãå€ãã®ç»é¢ãšã€ã³ã¯ãªã¡ã³ã¿ã«ããžãã¯ãåããéãäœæ¥ãéå§ãããŸã§ã¯æå¹ã§ãããã¢ããªã±ãŒã·ã§ã³ã¯ãŸããŸãé£ãããªããŸããããã©ãŒãã³ã¹ãåäžãããããã«ãshouldComponentUpdateãPureComponentãããŒã®äœ¿çšãã¡ã¢åãã«ãŒãã®æé©åãªã©ãããŸããŸãªæ¹æ³ãè©ŠããJSCoreã®çœ®ãæããæ€èšãå§ããŸããïŒHermesã¯ãŸã ãããŸããã§ããïŒããã®çµæãFlutterãè©ŠããŠã¿ããšããã¢ããã€ã¹ã«åºããããŸããã
Flutterã«ã¯ãããè±å¯ãªããŒã«ãããåªããããã©ãŒãã³ã¹ããããReactNativeã®åé¡ã¯ãããŸããããã¡ãããç§ã®RNã³ãŒããæãå®ç§ã§ã¯ãªããããããªãããšãåŠå®ããŠããããã§ã¯ãããŸããã
ç§ããããå§ããReactNativeã®é·æ
1. React Nativeã¯ã䟿å©ãªReact.jsã³ã³ããŒãã³ããã¬ãŒã ã¯ãŒã¯ã䜿çšããŸãã
React.jsïŒ
function App() {
return (
<div className="App">
<header className="App-header">
<Image
logo={logo}
/>
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<AppLink>
Learn React
</AppLink>
</header>
</div>
);
}
function Image({logo}) {
return <img src={logo} className="App-logo" alt="logo" />
}
function AppLink({children}) {
return (
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
{children}
</a>
);
}
export default App;
ãªã¢ã¯ããã€ãã£ãïŒ
function App() {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}
>
<Header />
</ScrollView>
</SafeAreaView>
</>
);
}
function Header() {
return (
<View>
<Text>head</Text>
</View>
);
}
const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
});
export default App;
2. WebViewããã³HTMLãªã-ãã€ãã£ãïŒOEMïŒãã©ãããã©ãŒã ãŠã£ãžã§ããã䜿çšãããŸãã JSãšãã€ãã£ãéšåã®éã®éä¿¡ã¯ãããªããžãä»ããŠè¡ãããŸãã
çŽ2幎åãWebViewåŽã«UIããŒããåããã¢ããªã±ãŒã·ã§ã³ãäœæããŸãããçµå±ã®ãšãããæ倧ã®èª²é¡ã¯ãããããã€ãã£ãã«ããããšãç¹ã«ã³ã³ããŒãã³ãã®å¿çæ§ãšã¹ã¯ããŒã«ã§ããããŸããOEMãŠã£ãžã§ããã䜿çšãããšããããã®åé¡ãèªåçã«è§£æ¶ãããŸãã
3. CodePushããŠãŒã¶ãŒãã¹ãã¢ããããŒãžã§ã³ãæŽæ°ããããšãªããã¢ããªã±ãŒã·ã§ã³ã³ãŒããã»ãŒå³åº§ã«å€æŽã§ããããã«ããŸãã
4.ãã®ååšã®éã«ãå€ãã®ã©ã€ãã©ãªãReactNativeçšã«ç»å ŽããŸããã
ã©ã€ãã©ãªã®ã³ã¬ã¯ã·ã§ã³ã®1ã€ã
æåã®ReactNativeãããžã§ã¯ãã§ã¯ãreact-native-fcmã©ã€ãã©ãªã䜿çšããŸããããã·ã¥éç¥ã®å Žåãéç¥ã®ã¿ãå¿ èŠã§ãä»ã«ã¯äœãå¿ èŠãããŸããã§ãããå¥ã®ãããžã§ã¯ãã§ã¯ãæã ã¯ãã§ã«äœ¿çšããåå¿ãããã€ãã£ãfirebaseããªããªã éç¥ã«å ããŠãåæãå¿ èŠã§ããã
ãã©ãã¿ãŒãã
1.ãªãªãŒã¹ããŸãã
å®å®ããä¿¡é Œã§ããããŒãžã§ã³ã DartãšFlutterã®åæãªãªãŒã¹ã«ãããæ°ããããŒãžã§ã³ã®Flutterãææ°ã®Dartã䜿çšããããã«ãªããŸãããããã¯åãäŒç€Ÿ-Googleã«ãã£ãŠéçºãããŠããã®ã§ã
2.UIã®ããã©ãŒãã³ã¹ã
UIã¯ç¬èªã®Skiaãšã³ãžã³ã§ã¬ã³ããªã³ã°ãããŸãã Flutterã«ã¯ããã©ãããã©ãŒã ã®OEMã³ã³ããŒãã³ãã®ã³ããŒã§ããç¬èªã®MaterialãŠã£ãžã§ãããšCupertinoãŠã£ãžã§ããã®ã»ããããããŸããããã«ãããäž¡æ¹ã®ãã©ãããã©ãŒã ã§åæã«äœ¿çšã§ããŸãããŠã£ãžã§ããã®åäœã®è©³çŽ°ã«ã€ããŠã¯ãFlutter Under theHoodã®èšäºãåç §ããŠãã ããã
äž¡æ¹ã®ãã©ãããã©ãŒã ã§iOSãŠã£ãžã§ãããèµ·åããäŸïŒ
OEMã³ã³ããŒãã³ããçžäºäœçšã®ã³ã¹ãã¯ãããŸããããããã¯ãWebViewã䜿çšãããã¯ãããžãŒã«å¯ŸããReact Nativeã®å©ç¹ã§ãããæè»æ§ãšããã©ãŒãã³ã¹ã¯FlutterãŠã£ãžã§ãããããå£ããŸããæè¿ãAndroidãšiOSçšã®ãããªã¢ã«ãŠã£ãžã§ãããäž»ã«äœ¿çšããã¢ããªã«åãçµã¿ãŸãããããã©ãããã©ãŒã ã«äŸåããDatePickerã§ãã
äž¡æ¹ã®ãã©ãããã©ãŒã ã®ãµã³ãã«UIïŒ
3ãããããªããŒã-æŽæ°ããããœãŒã¹ã³ãŒããã¡ã€ã«ãå®è¡äžã®Dartä»®æ³ãã·ã³ã«æ¿å ¥ããŸãããã®åŸãFlutterã¯ãŠã£ãžã§ããããªãŒãåæ§ç¯ããã¢ããªã±ãŒã·ã§ã³ãåèµ·åããã«å€æŽãããã«è¡šç€ºããŸããããã«ãããUIã¬ã€ã¢ãŠããšããžãã¯ã®èšè¿°ã«ãããæéãå€§å¹ ã«ç¯çŽã§ããŸãã
4.ãã©ãã¿ãŒã®ç·šéã
React Nativeã§ã¯ãJITã³ã³ãã€ã«ã®ã¿ãFlutterã¯éçºã¢ãŒãã§ã®ã¿JITã䜿çšããŸããããã«ãããããããªããŒããæ©èœããŸããFlutterã®ãªãªãŒã¹ãã«ãã¯ããã€ãã£ããã©ãããã©ãŒã ãã¡ã€ã«ãžã®AOTã³ã³ãã€ã«ã䜿çšããŸããããã¯ããªãªãŒã¹ã§JavaScriptã³ãŒãã«ã¢ã¯ã»ã¹ã§ããReactNativeãããå®å šã§å¹ççã§ããFlutterã®ãªãªãŒã¹ãã«ãã¯ãReactNativeã®ãªãªãŒã¹ãã«ããããã¯ããã«é«éã§ãã
ãã€ãã£ãvsãã©ãã¿ãŒvsReactãã€ãã£ãããã©ãŒãã³ã¹ã®æ¯èŒã
5.åé¢ããŸãã
Flutter and React Native 1ããã»ã¹ã§ã¯ã1ã€ã®éåæã¹ã¬ãããšéãã¿ã¹ã¯ãUIããããã¯ããŸãã
åºå£ïŒ
- éåææäœã«å解ããŸããUIããããã¯ããŸããããåãã¹ã¬ããã§å®è¡ãããŸãã
- åé¢ãžã®åé€ã¯ãç¬èªã®ãããŒãæã€ç¬ç«ããããã»ã¹ã§ãããããã¡ã€ã³ãããŒã®ãã®ãããã¯ã«ã€ããŠå¿é ããå¿ èŠã¯ãããŸããã
Flutter Dev Podcastã«ã¯ãåé¢æ ªãšããããæäœããããã®ã©ã€ãã©ãªã«é¢ããåªãããªãªãŒã¹ããããŸãã
6.ãã¹ãŠããŠã£ãžã§ããã§ãã
ãã®ãããã§ããŠã£ãžã§ããã¯ãç¹å¥ãªå¶éãªãã«ãéçºè ã®èŠæ±ã«å¿ããŠçžäºã«ãã¹ãã§ããŸãã
äŸïŒSwitchãšããã¿ã€ãã«ã®AppBarãå«ããã¿ã³ã
RaisedButton(
padding: const EdgeInsets.all(10),
child: AppBar(
title: Row(
children: <Widget>[
Switch(
value: false,
),
Text('text'),
],
),
),
),
ç¬èªã®ãŠã£ãžã§ãããäœæã§ããŸãã
- ãŠã£ãžã§ããã®çµã¿åããã
- ããè€éãªãžãªã¡ããªã«Canvasã䜿çšããã
- ç¹å®ã®åäœãå¿ èŠãªå Žåã«ã¬ã³ããŒã¬ã€ã€ãŒã䜿çšããã
æè¿ããŠã£ãžã§ããã¬ã€ã€ãŒã§ã¯ãªããRenderObjectã䜿çšããã¬ã³ããŒã¬ã€ã€ãŒã䜿çšããŠæãç°¡åã«å®è¡ã§ããæ©èœãäœæããŸãããããããããã«ã€ããŠã¯ã次ã®èšäºã®1ã€ã§èª¬æããŸããããã§ã¯ãåé¡ãšãã®è§£æ±ºçã«ã€ããŠèª¬æããŸããã¬ã³ããŒã¬ã€ã€ãŒ
ã«é¢ããèšäºã
ReactNativeã®çæ
1.ãŸã 1.0.0ã§ã¯ãããŸããã
éåžžããããžã§ã¯ãã§ã¯ãç¹å®ã®RNããŒãžã§ã³ã«ãšã©ãŸããŸãããæŽæ°ã«ãããã©ã€ãã©ãªãŸãã¯RNå éšããã€ã¹ãç ŽæããããšããããããŸãããèªåããŒãžã§ã³æŽæ°ããŒã«ã倱æããŠããŸãããã¢ãŠããœãŒã·ã³ã°ã®é¡§å®¢ã¯æŽæ°ã«è²»ãããæéã®æ¯æããè¡ããªããããæ°ããããŒãžã§ã³ã§ãããžã§ã¯ããåäœæããæ¹ãé«éã§ããã
ãããã¯ãå¿ èŠãªã©ã€ãã©ãªã§å¿ èŠãªå Žåã«ã®ã¿æŽæ°ãããããæ°ããããŒãžã§ã³ã§é倧ãªãã°ãä¿®æ£ãããŸããããã®å Žåãå€ãã©ã€ãã©ãªãæ°ããããŒãžã§ã³ã®ReactNativeãšäºææ§ããªãå¯èœæ§ããããšãããªã¹ã¯ããããŸãããã§ããã1幎åçµã¡ãŸããã®ã§ãä»ããã©ããã£ãŠç¢ºèªããŸããããã客æ§ã®æéã¯ç§ãã¡ã«ãšã£ãŠéèŠãªã®ã§ãæ°åã§ReactNativeãæŽæ°ããŠã¿ãŸãããã
v0.61.5ïŒçŸæç¹ã§ã¯æåŸãã2çªç®ïŒã§ReactNativeãããžã§ã¯ããäœæããŸãã
react-native init test_version --version 0.61
å®è¡ïŒ
ãã¹ãŠåé¡ãããŸããã
ã¢ããã°ã¬ãŒãã¯Gitäžã§æ©èœããããããªããšãšã©ãŒãçºçããããããªããžããªãåæåããŸã
ãnpxreact-nativeã¢ããã°ã¬ãŒããå®è¡ããŸãã
ã¯ãªãŒã³ãªãããžã§ã¯ãã¯ã¢ããã°ã¬ãŒãæã«ãšã©ãŒãã¹ããŒããŸãããã¬ããã«ã§æäŸãããŠ
ãããªã³ã¯ããã©ã£ãŠã¿ãŸããããæåã§æŽæ°ãããã¡ã€ã«ã®ãªã¹ãïŒ
- package.json
- .gitattributes
- .flowconfig
- App.js
- app.js / android / app / build.gradle
- android / app / src / debug / java / com / rndiffapp / ReactNativeFlipper.java
- android / app / src / main / AndroidManifest.xml
- android / app / src / main / java / com / rndiffapp / MainApplication.java
- android / build.gradle
- android / gradle.properties
- android / gradle /ã©ãããŒ/gradle-wrapper.properties
- android / gradlew
- ios / Podfile
- ios/RnDiffApp.xcodeproj/xcshareddata/xcschemes/RnDiffApp-tvOS.xcscheme
- ios/RnDiffApp.xcodeproj/xcshareddata/xcschemes/RnDiffApp.xcscheme
- ios/RnDiffApp/AppDelegate.m
ãã¡ã€ã«ãæŽæ°ããåŸãupgradeã
å®è¡ããŸããnpminstallãå®è¡ããŸããå®äºããããžã§ã¯ããæŽæ°ãããŸããã
äž»ãªåºæºã¯æéã§ããåé¡ã®æŽæ°ãšä¿®æ£ããŸãã¯ãããžã§ã¯ãã®æåããã®åæ§ç¯ã«è²»ããããŸãã Flutterã§ãã³ã³ãœãŒã«ã«ãflutterupgradeããšå ¥åããã°å®äºã§ãã Flutterã¯ããã¹ãŠã®ãããžã§ã¯ãã«å¯ŸããŠäžåºŠã«æŽæ°ãããŸããé倧ãªå€æŽããããããããŸããããéåžžããããžã§ã¯ãå šäœã§ããã€ãã®å€æŽããããä¿®æ£ã¯éåžžã«ç°¡åã§ãã
2.ããã©ãŒãã³ã¹ã
ããã¯ååã§ã¯ãããŸããã§ãããããã§ãç§ãã¡ãæãã»ã©éãã¯ãããŸããããã¹ã¿ãŒã¯åžžã«äœããéãã€ãã£ããããã©ãŒãã³ã¹ãçèŽããŠããŸãããæé©åãåžžã«åœ¹ç«ã€ãšã¯éããŸããã§ãããã¢ããªã±ãŒã·ã§ã³ã倧ãããªããšãããªããžçšã«ã·ãªã¢ã«åãããããŒã¿ãå¢ããå¿çæ§ãäœäžããŸãã
3.ãã€ãã£ãã³ã³ããŒãã³ãã䜿çšãããŠãããããAndroidãšiOSã§ã¯å€èŠ³ãç°ãªããŸãã
äžè²«æ§ãå®çŸããã«ã¯ãäžæ¹ã®ãã©ãããã©ãŒã ã®ã³ã³ããŒãã³ãã®ã¢ããã°ãäœæããããäž¡æ¹ã®ãã©ãããã©ãŒã ãæåããäœæããå¿ èŠããããŸãããŸãã¯ããããã®æ©èœãšéããèæ ®ããŠèšèšãèšèšããŸãã
åãUIãå·ŠåŽãIOSãå³åŽãAndroidã§ãã
ããã«
JavaScriptCore
React Nativeã«ã¯ãAndroidçšã®å€ãJSCoreãé·ãéãããŸããããšã«ã¡ã¹ã®ç»å Žã«ããç¶æ³ã¯æ¹åããŸããããããªãã¿ã®éçºè ããã¹ãã®ã¬ãã¥ãŒããå€æãããšããã¹ãŠãããã»ã©åçŽã§ã¯ãããŸããã
JSãšã³ãžã³ã®æ¯èŒã
å芧äŒ
ãããè³åŠäž¡è«ã«åž°ããã®ã¯é£ãããç®±ããåºããŠããã«éèŠãªã©ã€ãã©ãªãšæ©èœãæäŸããŸãããé·æãäžåããç¬èªã®åé¡ããããŸããExpoãŸãã¯ãã€ãã£ãã³ãŒãã䜿çšããå€éšã©ã€ãã©ãªã«æ¬ ããŠãããã©ââãããã©ãŒã ã¬ãã«ã®æ©èœãå¿ èŠãªå Žåã¯ããããžã§ã¯ããããã·ã¥ããå¿ èŠããããExpoã®é·æãæ¶ãããçæã«ãªããŸãããã€ãã£ãinitãšExpoãåå¿ãããŸãã
ãã©ãã¿ãŒã®çæ
ãããã¯èšããŸã§ããªãäžå ¬å¹³ã§ããããããã§ããããã¯ç¹å¹è¬ã§ã¯ãããŸããã
1.ã¹ãã·ã£ãªã¹ããšæ¬ å¡ãå°ãªããªããŸãã
React Nativeãšæ¯èŒããŠãFlutterãããŒã¹ã«æ§ç¯ããŠããéçºè ãäŒæ¥ã¯å°ãªãã2019幎5æã«Flutterã§ä»äºãæ¢ããŠãããšãããã£ã3瀟ã«åºããããŸããã
2.ã©ã€ãã©ãªã®æ°ã¯ReactNativeãããå°ãªããªã£ãŠããŸãã
Flutterã¯è¥ããã¯ãããžãŒã§ããããããã®ããã®ã©ã€ãã©ãªã¯ã¯ããã«å°ãªããªã£ãŠããŸããããã®æ°ã¯æŽ»çºã«å¢ããŠããŸããããããå¿ èŠãªã©ã€ãã©ãªããã¹ãŠå©çšã§ããã®ã§ã1幎以äžã®äœæ¥ã§ãããã«ãã£ãŠç¹å¥ãªåé¡ãçºçããããšã¯ãããŸããã§ããã
3.以äžã«ã¯é©ããŠããŸããïŒ
- ã²ãŒã ã
- éã§ã®äœæ¥ã«é¢é£ããã¢ããªã±ãŒã·ã§ã³ã
- æ¡åŒµçŸå®ã¢ããªã±ãŒã·ã§ã³ããã©ãããã©ãŒã ããšã«åå¥ã«ããžãã¯ãå®è£ ããå¿ èŠãããããã§ãã
ãã ããäžè¬çãªUIãå€æ°ããå Žåã¯ããã©ãããã©ãŒã ãã£ãã«ã䜿çšããŠãã€ãã£ãã³ãŒããæäœããããFlutterããã€ãã£ãã¢ããªã±ãŒã·ã§ã³ã«çµ±åãããªãã·ã§ã³ã§ååã§ãã
ããã¥ã¡ã³ããŒã·ã§ã³
React Nativeã«ã¯ãçºçããå€ãã®è³ªåã«çããéåžžã«åªããããã¥ã¡ã³ãããããŸããããã¯åŸã ã«æ¹åãããŠããïŒä»¥åã¯ã空çœã®ããŒãžã«åºãããå¯èœæ§ããããŸãããã¿ã€ãã«ã¯ãããŸãããã³ã³ãã³ãã¯ãããŸããïŒãçŽ æã¯æ¹åãããŠããŸãã
Flutterã§ã¯ãããã¥ã¡ã³ãã¯çŽ æŽãããã§ããäŸã説æãäŸãå«ãã¬ã·ãããããªãäœãã®äœ¿çšã«åé¡ãããå Žåãããã¥ã¡ã³ãã¯ããã解決ããããšãã§ããŸãã
ãšã³ããªã®ãããå€
ã©ã¡ãã®å Žåãããšã³ããªã®ãããå€ã¯éåžžã«äœããªã£ãŠããŸãã
- React Native-JSãReactãç¥ã£ãŠããå¿
èŠããããå§ããããšãã§ããŸãã
- Flutter â JS / Java / Kotlin / Swift / C ( JS â ), Dart .
React Native, Flutter .
React Native
- .
- .
- .
- .
- .
Flutter
- , . .
- , .
- .
- .
- .
ãŠãŒã¶ãŒã¯ããããã¯ãŒã¯èŠæ±ã®HttpãŸãã¯Dioã«äœã䜿çšããããæ°ã«ããŸããã
ãã®æ¥ã®JSéçºè ãŸãã¯ä»æã®Flutteréçºè ãæ¢ããŠããŸããããäž»ãªããšã¯ãã¢ããªã±ãŒã·ã§ã³ãå¿ èŠãªã¿ã¹ã¯ãå®è¡ããçç£æ§ãé«ãããšã§ããFlutterã䜿çšãããšããããã®èŠä»¶ãã¯ããã«å¹ççã«æºããããšãã§ããŸãã
FlutterãšReactNativeã䜿çšããŠåãåé¡ã解決ããåæã¯ãèšäºã®åŸåã«ãããŸãã