java getConstants在React native中
我正在努力学习母语的发展
我正在经历React Native docs它说
An optional method called getConstants returns the constant values exposed to JavaScript. Its implementation is not required but is very useful to key pre-defined values that need to be communicated from JavaScript to Java in sync
用下面的片段
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
return constants;
}
从上面的定义中,我可以看出这个pass常量一次性使用了从Javascript到java的信息(比如api密钥)
为了证实这一点,我去了react-native-mapsrepo
我看到他们是这样用的
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("legalNotice", "This license information is displayed in Settings > Google > Open Source on any device running Google Play services.");
return constants;
}
它不会消耗任何通过的东西
有人能再详细解释一下上面的定义吗?它使用什么(getConstants()
方法)
共 (0) 个答案