从 JavaScript 代码内部 React Native 访问 strings.xml [英] React Native access strings.xml from inside javascript code

查看:28
本文介绍了从 JavaScript 代码内部 React Native 访问 strings.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 Javascript 代码内部的 android/app/src/main/res/values/strings.xml 访问当前值?我想为每个构建放置不同的端点 URL,但我什至无法在 react-native 代码中检测构建类型,而不必求助于 __DEV__ 变量(可以从开发菜单中关闭)

Is there a way to access the current values from android/app/src/main/res/values/strings.xml from inside Javascript code? I want to place different endpoint URLs for each build, but I'm failing even to detect the type of build inside react-native code without having to resort to the __DEV__ variable (which can be turned off from the dev menu)

推荐答案

唯一可能的方法是使用本机模块构建桥梁,https://facebook.github.io/react-native/docs/native-modules-android.html.本质上,您可以将 JS 中的字符串传递给本机模块,并让本机函数处理要抓取的字符串并将其传递回 JS.

The only way this might be possible would be building a bridge using native modules, https://facebook.github.io/react-native/docs/native-modules-android.html. Essential you can pass strings in JS to the native modules and have native function handle which string to grab and pass back to JS.

这篇关于从 JavaScript 代码内部 React Native 访问 strings.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆