标签: react-native-android

React-Native:如何缩放字体大小以支持Android和iOS中的许多不同分辨率和屏幕?

我试图在现有的许多不同屏幕上找到正确的字体大小,我遇到了很大的麻烦.

目前我有一个名为的辅助函数getCorrectFontSizeForScreen.

export function getCorrectFontSizeForScreen(currentFontSize){

  const maxFontDifferFactor = 6; //the maximum pixels of font size we can go up or

  if(Platform.OS === 'ios'){    //iOS part
    let devRatio = PixelRatio.get();
    this.fontFactor = (((screenWidth*devRatio)/320)*0.55+((screenHeight*devRatio)/640)*0.45)
    if(this.fontFactor<=1){
      return currentFontSize-float2int(maxFontDifferFactor*0.3);
    }else if((this.fontFactor>=1) && (this.fontFactor<=1.6)){
      return currentFontSize-float2int(maxFontDifferFactor*0.1);
    }else if((this.fontFactor>=1.6) && (this.fontFactor<=2)){
      return currentFontSize;
    }else if((this.fontFactor>=2) && (this.fontFactor<=3)){
      return currentFontSize+float2int(maxFontDifferFactor*0.85);
    }else if (this.fontFactor>=3){
      return currentFontSize+float2int(maxFontDifferFactor);
    }
  }else{    //Android part

    let scale = screenWidth/375;  //got this from the f8 facebook project

    this.fontFactor = (((screenWidth)/320)*0.65+((screenHeight)/640)*0.35)

    if(this.fontFactor<=1){   //for …
Run Code Online (Sandbox Code Playgroud)

android ios react-native react-native-android

5
推荐指数
1
解决办法
2419
查看次数

React-Native Android - 如何使用getRealDimensions(尺寸不起作用)

经过大量研究后,我发现Android的Dimensions库不能像预期的那样工作.例如,每次我使用"Dimensions.get('window').height"时,我会得到不同的结果.

这是在git:
Dimensions.get('window')上记录的.在Android上,高度有时是错误的

解决方案是使用上面git链接中提到的"getRealDimensions"库.

这是'getRealDimensions'的链接,但它是用java编写的,我不知道如何将它实现到我的react-native android项目中.

总结
如何在我的react-native android项目中实现'getRealDimensions'库?

谢谢.

android react-native react-native-android

5
推荐指数
2
解决办法
3179
查看次数

react-native android项目中keystores文件夹的用途是什么

我目前正在努力与本机反应。我已经成功生成了singed APK,遵循docs中提到的步骤。我发现react-native android的目录结构与android-studio不同。react-native android项目中有一个名为keystore的文件夹。该文件夹的用途是什么?我需要将密钥库保留在其中吗?当医生说将密钥库文件放置在android / app目录下时。

请分享您的想法。谢谢。

在此处输入图片说明

keystore android-keystore react-native react-native-android

5
推荐指数
1
解决办法
1640
查看次数

使用Expnent React Native登录Facebook

需要帮助的人,当前正在使用指数并访问Exponent.Facebook.logInWithReadPermissionsAsync进行身份验证。任何人都有设置项目的指南。我找不到iOS文件夹,因为在fa​​cebook sdk的说明中,我需要在项目上添加一些库。这是我的main.js:

import Expo from 'expo';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Button } from 'react-native-elements';

class App extends React.Component {

  authenticate = (token) => {
    const provider = firebase.auth.FacebookAuthProvider;
    const credential = provider.credential(token);
    return firebase.auth().signInWithCredential(credential);
  }

  login = async () => {
    const ADD_ID = 273131576444313
    const options = {
        permissions: ['public_profile', 'email'],
    }
    const {type, token} = await Expo.Facebook.logInWithReadPermissionsAsync(ADD_ID, options)
    if (type === 'success') {
        const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`) …
Run Code Online (Sandbox Code Playgroud)

exponent react-native react-native-android react-native-ios expo

5
推荐指数
1
解决办法
3111
查看次数

无法将“ gradlew.bat”识别为内部或外部命令

所以我试图基于入门React Native在Windows 10中启动一个react native android项目。我被困在最后一步-> react-native run-android

命令提示符的屏幕截图

ps:我为我的Android模拟器棉花糖6.0使用genymotion

gradlew react-native react-native-android

5
推荐指数
1
解决办法
1万
查看次数

如何设计与所有设备兼容的本机屏幕

我正在尝试设计这个设计react-native.这就是我为此编写的内容,但这不是我想要的.这仅适用于一个屏幕,如果我更改屏幕大小,则事情不起作用.

这看起来像绝对布局.我应该做些什么改变才能使它适用于所有屏幕尺寸.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from "react";
import {
  AppRegistry,
  Image,
  View,
  Text,
  Button,
  StyleSheet
} from "react-native";

class SplashScreen extends Component {
  render() {
    console.disableYellowBox = true;
    return (
      <View style={styles.container}>
        <Image
          source={require("./img/talk_people.png")}
          style={{ width: 300, height: 300 }}
        />
        <Text style={{ fontSize: 22, textAlign: "center", marginTop: 30 }}>
          Never forget to stay in touch with the people that matter to you.
        </Text>
        <View …
Run Code Online (Sandbox Code Playgroud)

android react-native react-native-android react-native-flexbox react-native-ios

5
推荐指数
1
解决办法
4658
查看次数

构建无法解析类com.android.build.output文件react-native

我正在使用React-Native在Android上运行我的应用程序,并且出现下一个错误:

“构建文件'C:\ Users ........ \ android \ app \ build.gradle':3:无法解析com.android.build.OutputFile类”

我已经尝试过使用Android Studio和GenyMotion,但是问题是相同的。

有人知道会发生什么吗?

谢谢 !!

android react-native-android

5
推荐指数
2
解决办法
4358
查看次数

React Native Navigation - [FAB]浮动操作按钮未按预期显示

我正在使用React-native-navigation(wix),并且存在与React本机FAB(浮动操作按钮)相关的问题.

要求 - 我需要在componentDidMount生命周期方法中设置FAB,如下所示

componentDidMount() {
  this.props.navigator.setButtons({
    fab: {
     collapsedId: "someFormName",
     ...getAddButtonStyle()
    }
  });
}
Run Code Online (Sandbox Code Playgroud)

我管理this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));全球,它按预期工作.我在这里遇到的问题是当我将其设置在内部时,FAB没有在我的UI中显示,componentDidMount()但如果我设置为 static button完美的工作.此外,它完美地完成了内部render()功能.

我很困惑,为什么我不能在componentDidMount()[初始页面加载] 内设置按钮?

android react-native react-native-android react-native-navigation wix-react-native-navigation

5
推荐指数
0
解决办法
449
查看次数

在本机中在哪里使用后台地理位置服务

我才刚开始学习本机

我有

  • App.js
  • Navigation.js

我有两个屏幕

  • SplashScreen.js

  • Login.js

在App.js上

const App = () => (
  <Nav  />
);

export default App;
Run Code Online (Sandbox Code Playgroud)

Navigation.js

const Nav = createStackNavigator({
    loginScreen: { screen: Login },
    splashScreen: {screen: SplashScreen}
},
{ 
    initialRouteName: 'splashScreen',
})
export default createAppContainer(Nav);
Run Code Online (Sandbox Code Playgroud)

在splashscreen.js上

componentWillMount(){
    setTimeout(() => {
        this.props.navigation.navigate("loginScreen");
    }, 3000);
}
Run Code Online (Sandbox Code Playgroud)

到现在为止一切运转良好

现在,我开始使用以下方法实施后台地理位置跟踪

https://github.com/mauron85/react-native-background-geolocation/tree/0.4-stable

为了进行测试,我将其放置在login.js中

import React, { Component } from "react";
import Contacts from 'react-native-contacts';
import { Image, StyleSheet, Text, TouchableOpacity, View, Button, PermissionsAndroid } from "react-native";
import { appContainer, …
Run Code Online (Sandbox Code Playgroud)

background geolocation react-native react-native-android

5
推荐指数
1
解决办法
1012
查看次数

反应本机链接路径不正确

我有一个应用程序无法链接/取消链接包,类似于此问题。

特别是在链接MainApplication.java此错误文件时失败。

错误取消链接时出了点问题。原因:没有这样的文件或目录,请打开“ ./AppName/android/app/src/main/java/co/AppName/AppName/MainApplication.java”

该路径实际上是不正确java/co/AppNAme应该是java/com/AppName。

我在任何地方都找不到导致此问题的原因,也找不到任何有关如何设置路径的文档。

我尝试使用babel-plugin-module-resolver但没有成功,除非我错过了一些东西。有人有类似的问题吗?

java react-native react-native-android react-native-linking

5
推荐指数
1
解决办法
64
查看次数