本文介绍了反应本机&安卓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将React Native用于新的Web应用程序.可以同时使用它发布iOS和Android应用程序吗?

I'm contemplating on using React Native for a new web app. Is it possible to ship both iOS and Android apps using it?

我知道它正在开发中,但是我不清楚它是否将是一个单独的开源项目(例如React Android与React Native),还是仅仅是一个开源项目(例如React Native).

I know that it's on the roadmap, but it's unclear to me whether it's going to be a separate open-source project (e.g., React Android vs React Native), or just one (e.g., React Native).

推荐答案

TLDR :很有可能.但这取决于您的用例.

TLDR: Most likely you can. But it depends on your use cases.

您可以争取实现 80〜99 +%的代码重用(取决于您使用的Android/iOS本机视图/模块的数量,例如,是否具有自定义图形代码或低级TCP网络代码;这些代码只能在本机代码中完成;并且作为API公开给您的JS代码.特定于平台的JS代码的数量实际上很少.此外,您还可以使用平台检查(如if (Platform.OS === 'android'){}来解决该问题)重用,这是非常好的. Dropbox和其他公司也做了类似的项目:使用c ++在iOS和Android项目之间构建共享"组件,同时在本机iOS(Objective-c或swift)和Android(java)中实现大多数UI代码.但是现在您正在使用Java和Objective-C或Swift来进行C ++,需要掌握更多的语言,更多的复杂性和更多的精力.为了使不同的本机代码在iOS和Android中都能正常工作,还可能需要采取一些艰巨的动作,例如调试...

You can aim for about 80~99+% code reuse (depending on how much Android/iOS native views/modules you use eg. Do you have custom graphics code or low-level TCP networking code; Those can only be done in native code; And expose as API to your JS code. The amount of the platform-specific JS code is actually minimal. Plus you can also use platform check like if (Platform.OS === 'android'){} to solve that) of code reuse, which is pretty nice. Dropbox and other companies have done similar projects: using c++ to build a 'shared' component between iOS and Android project, while implementing most of the UI code in native iOS(Objective-c or swift) and Android(java). But now you are doing C++ with Java and Objective-C or Swift, more language to master, more complexity and more brain juice went down the drain. And it probably took some super tough gymnastic move to make different native code work in both iOS and Android, plus debugging...

React Native仅使用JavaScript编写几乎所有内容变得容易得多.但是有一个陷阱,只能共享大约80%的JS代码.在可预见的将来,您仍然需要为Android和iOS版本编写特定于平台"的JS代码.

React Native just makes it a lot easier to write almost everything in JavaScript. But there is a catch, only about 80% of the JS code could be shared. In the foreseeable future, you still need to write 'platform-specific' JS code for Android and iOS versions.

这就是为什么FB表示他们的目标是学习一次,在任何地方编写代码" ,而不是在任何地方运行".

That's why FB said they aim for 'Learn once, code anywhere' instead of 'run' everywhere.

但是除了代码重用以外,它还是非常不错的( 80 %%以上的代码重用与维护2个完全不同的版本(Android和iOS ya相比还是一个很大的进步)

But it's still very nice other than code reuse(80+% code reuse is still a big improvement comparing to maintaining 2 entirely different versions: Android and iOS ya?)

Cmd + R刷新应用程序可极大提高开发速度.等待大型项目的编译只会让您感到自己快死了.

Cmd +R to refresh the app is a GREAT boost for development speed. Waiting for a big project to compile just makes you felt you were dying inside.

由于使用React而获得的免费声明性UI.这是另一个很棒的优点!.因为您不再需要挖掘"特定的UI代码了.资料变更了吗?只需刷新"它,UI就会相应地更新.没有浪费脑汁.

Declarative UI you get for free, because of using React. This is another great plus! As you don't need to 'dig' into your specific UI code that often anymore. Data changed? Just 'flush' it and UI just update accordingly. No brain juice wasted.

只是将不太复杂的Android React Native App移植到iOS .我花了 3天.对于App的要求和iOS版本的请求是突然而没有计划的.因此,如果我也为iOS设计了Android计划,那肯定会更快. 巨大的胜利:)

I just ported my not so complicated Android React Native App to iOS. And it took me 3 days. The request for and iOS version for the App came as a rather abrupt and unplanned move. So could definitely be even faster had I built the Android with a plan for iOS too. Huge win:)

另一个很大的好处就是可以进行热代码推送,而无需经历令人讨厌的1周应用商店审查过程.因此,不再有其他问题,是的,我们的应用程序已获批准.让我们发布.哦,谢伊特.严重的错误,我们的应用程序不断崩溃(至少在修复生效前一周会发生).而且您必须乞求苹果加快速度这个过程".这是可能的,因为代码库的主要部分将使用JS以及 AppHub CodePush ,您几乎可以立即将代码部署到您的用户.这是苹果有条件所允许的.

Another great benefit is able to do hot code push without going through the hellish 1 week app store review process. So no more, "YAY, our app is approved. Let's release. Oh Shiiit. Critical bug and our app keeps crashing(that's gonna keep happening for at least a week before your fix is live). And you have to beg Apple to speed up the process". This is possible because the major part of the code base would be written in JS and with tools like AppHub or CodePush, you could almost instantly deploy code to your users. This is conditionally allowed by Apple.

最后,作为一个开源项目,项目寿命往往是一个令人担忧的问题.对于React Native来说不是问题. React Native由(FB Ads Manager)内部使用,并由FB(十几位FB工程师?)在Facebook的支持下,拥有近500位贡献者和25k星,React Native充满生机.眼见为实:)( https://github.com/facebook/react-native )

Lastly, as an open-source project, project longevity tends to be a concern. Not an issue for React Native. Internally used by(FB Ads Manager) and backed by FB(a dozen FB Engineers?) by Facebook, with close to 500 contributors and 25k Stars, React Native is full of life. Seeing is believing :) (https://github.com/facebook/react-native)

编辑1

我意识到我显然有偏见,只谈论了关于React Native的好东西.因此,请结帐 https://productpains.com/product/react-native/和Github要全面了解问题.肯定不是不是灵丹妙药.话虽如此,它可以满足我的大多数用例,而且我很快就看不到我使用本机iOS或Android.

I realized that I am apparently a bit biased and only talked about the good stuff about React Native. So do checkout https://productpains.com/product/react-native/ and Github issues to have a full picture. It's definitely not silver bullet. That being said, it satisfies most of my use case and I couldn't see me use native iOS or Android anytime soon.

编辑2 Facebook(duh ..)发布的Facebook F8会议应用程序是100%开放源代码,并且它们有一个非常不错的教程,向您展示如何拥有两者 iOS和Android本机体验(90%的良好体验)作为本机?),同时实现了85%的代码重用.检查一下-> https://makeitopen.com

EDIT 2The Facebook F8 conference app released by Facebook (duh..) is 100% open source and they have a really nice tutorial to show you how you could have both iOS and Android native experience(90% as good as native ?), and at the same time, achieved 85% code re-use. check it out --> https://makeitopen.com

编辑3 您可能还想查看Flutter及其优点和优点;缺点:)

EDIT 3You may also want to checkout Flutter and its pros & cons :)

这篇关于反应本机&安卓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 07:47