Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all 30345 articles
Browse latest View live

React Native: onPress in Android side somehow triggers onNavigationStateChange

$
0
0

I have some code that I implemented a couple of months ago that fixed the ability for a user to who was reading an article on my app and wanted to click on a hyperlink inside that article, once having done so, the user would be taken to an external browser. This is the implementation:

<View style={styles.content}>
            {Boolean(this.props.article.VideoID) && (
              <VimeoVideo videoId={this.props.article.VideoID.toString()} />
            )}
            {Boolean(this.props.article.Summary) && (
              <Text style={styles.boldParragraph}>
                {this.props.article.Summary}
              </Text>
            )}
            {this.props.article.Sections.map(s => (
              <WebViewAutoHeight
                key={s.Body.substr(10)}
                source={{
                  //prettier-ignore
                  html: `<body style="font-family: -apple-system, Roboto, sans-serif; background-color: ${lightTheme.grey2} !important; color: ${v2Colors.charcoalDarkest}; font-size: ${moderateScale(14, 0.2)}px;">${s.Body}</body>`
                }}
                // onNavigationStateChange={event => {
                //   if (event.url !== uri) {
                //     Linking.openURL(event.url);
                //   }
                // }}
              />
            ))}
          </View>

The commented out part. It works for iOS but on Android, as soon as the user clicks on READ MORE, it takes them to open up another browser in their phone not sure of the connection because onPress={mainActionButtonPress} is what the user is pressing and mainActionButtonPress is connected to a function:

 _goto = article => {
    this.props.setSelectedArticle(article);
    this.props.navigation.navigate("ArticleDetails", { isRead: true });
  };

how is onNavigationStateChange property inside of AutoHeightWebView being triggered by the _goto function?


React native: "only the original thread that created a view hierarchy can touch its views"

$
0
0

enter image description herepressing the button to get the base64 string of the svg ... produces the following error: - Only the original thread that created a view hierarchy can touch its views

render() {
    return (
      <ScrollView contentContainerStyle={styles.container}>
        <Svg
          ref={c => (this.svg = c)}
          height="50%"
          width="50%"
          viewBox="0 0 100 100">
          <Circle
            cx="50"
            cy="50"
            r="45"
            stroke="blue"
            strokeWidth="2.5"
            fill="green"
          />
        </Svg>

        <TouchableOpacity
          onPress={() => {
            this.svg.toDataURL(data => {
              console.log("data", data);
            });
          }}
        >
          <Text>Get Data</Text>
        </TouchableOpacity>
      </ScrollView>
    );
  }

Any help?

Couple filters in react-native-firebase [duplicate]

$
0
0

This question already has an answer here:

I am creating RN app with react-native-firebase, using Firebase Realtime Database as my DB. It is like tinder app and I want to apply a couple of filters while fetching users from the backend (for example I want to fetch users with defined age thresholds, distance from me, etc.).

How can I make a couple of filtering with react-native-firebase? Also how can I get request users only with defined destination from me?

compileSdkVersion is not specified error in React Native Android

$
0
0

I get the build error when I try to build an Android app in my React Native project.

When I run react-native run-android, it says:

> Configure project :react-native-os
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-os'.
> compileSdkVersion is not specified.

In Android Studio, I can see that it says the same thing: Cause: compileSdkVersion is not specified.

So I edited build.gradle(Module: app) file in Android Studio, but the problem persists and the error message doesn't change.

android {
//    compileSdkVersion rootProject.ext.compileSdkVersion
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

I tried solutions in other threads like this one but nothing worked. Does anyone know what the problem is here?

Network request started failing in production app with No valid NAT64 prefix error over WIFI but works on mobile data, Android only

$
0
0

We started getting a Network Request Failed error in our production app when users try to login on WiFi, mobile data never has this issue. It occurs on most but not all WiFi networks. We have pushed no changes to our app recently and it only occurs on Android. Pertinent logcat message is No valid NAT64 prefix. Any ideas what could happening?

How to use react-native-quikkly?

$
0
0

I recently integrated react-native-quikkly to my app. While working with it, I have some questions. I can't see the original image in rendered image. I can get svg file data using 'createImage' function.

Quikkly.createImage({
  value: 123456,
  template: "template0002style11",
  skin: {
    backgroundColor: '#5cb7a6',
    borderColor: '#ffffff',
    dataColor: '#000000',
    maskColor: '#5cb7a6',
    overlayColor: '#ffffff',
    imagePath: 'https://s3-eu-west-1.amazonaws.com/docs.quikkly.io/img/1481647718.png'
  }
}).then((result) => {
  console.log(result)
})

Here, I tried to set imagePath as weburi, local storage path. But nothing worked. I want to know the reason and how to set imagepath. And also I need to use custom blueprint file. But I can't get any document about how to set custom blueprint file in react-native. Anyone who is good at quikkly, please help me.

Transparent backgroundColor for an Image using React Native on Android

$
0
0

I have an asset with transparent background being used on our app. While on iOS, setting backgroundColor: 'transparent' for the Image component works as expected, on Android, it always gets rendered with a light grey background.

In fact, backgroundColor value seems to be completely ignored on Android.

This is how it looks right now:

enter image description here

<View style={styles.cardHeader}>
  <Image
    source={require('../assets/images/greeting.png')}
    style={styles.greetingImage} />
</View>

Styles:

cardHeader: {
  alignSelf: 'stretch',
  backgroundColor: Color.GREY,
  paddingTop: 30,
  borderTopLeftRadius: 5,
  borderTopRightRadius: 5
},

greetingImage: {
  alignSelf: 'center',
  backgroundColor: 'transparent'
}

How to I solve "Found corrupted package.xml at C:\Users\ideapad\AppData\Local\Android\Sdk\build-tools\28.0.3\package.xml" in react native

$
0
0

Here is my react native environmentSystem: OS: Windows 10 10.0.17134 CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz Memory: 1.56 GB / 7.85 GB Binaries: - Node: 10.16.2 - C:\Program Files\nodejs\node.EXE - Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD - npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD

IDEs: Android Studio: Version 3.5.0.0 AI-191.8026.42.35.6010548 npmPackages:

  • react: 16.9.0 => 16.9.0
  • react-native: 0.61.5 => 0.61.5

This error is generated every time I run react-native run-android or any other react-native command

I have tried gradlew clean, I have tried to delete the .gradle file, I have searched the internet but found no solution to this problem.

A day before it was all working fine until the next morning when I powered on my pc.


React Native - change icon color on press

$
0
0

When the 'check' icon is being pressed, I want it to change color from default red to green. In my case, while I have another function for onpress, I use this conditional color statement

<Icon name="check" size={20} color={this.state.isCompleted ? '#1DA664' : '#DE5347'} onPress={() => this.isCompleted(rowData)} isCompleted={this.state.isCompleted}/>

I call this function for onpress

isCompleted(rowData){
     if (this.state.status != 'new'){
  this.itemsRef.child(rowData.id).update({
    status: 'completed'
  });
  this.setState({
    isCompleted: true
  })
}
}

When one of the icon in a list view is pressed, the icon changed color but everytime the color change is the icon of last item.

As shown in pic,

enter image description here

When I press on item 'cook lunch' , it should be the icon in cook lunch turn to green. Instead, the icon in the last item 'hello' changed. Totally clueless of what did wrong. Appreciate if someone to guide me.

Thanks in advanced.

building android apps, without android studio, on "windows"

$
0
0

I am an "ABSOLUTE" beginner into this Android development world. I have no knowledge, and i am daring to jump here to ask the question, so pls dont shoot me!

Well, I have my hands on React JS, so naturally, I got inclined to React Native for android development, only to find out that it is very 'fast changing target' and requires Android Studio (maybe) :( .

Help me with this!

I want to learn android development, without any android studio stuff (:| I only have 2GB RAM Laptop) I dont fear learning Java, and I can do anything for app development.

Plz suggest me any language framework to build apps, (js, python or java), of course without android studio...

React-native android project with many error: Could not find class 'android.XXX'

$
0
0

I have a react-native project which should support minimum SDK version of 16 and is androidX but I get these errors using android studio logcat:

 E/dalvikvm: Could not find class 'android.os.UserManager', referenced from method androidx.core.os.UserManagerCompat.isUserUnlocked
 12-21 16:19:25.003 12695-12695/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.wrappers.PackageManagerWrapper.zzb
 12-21 16:19:25.153 12695-12719/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method androidx.core.app.AppOpsManagerCompat.noteOp
 12-21 16:19:25.153 12695-12719/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method androidx.core.app.AppOpsManagerCompat.noteOpNoThrow
 12-21 16:19:25.153 12695-12719/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method androidx.core.app.AppOpsManagerCompat.noteProxyOp
 12-21 16:19:25.153 12695-12719/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method androidx.core.app.AppOpsManagerCompat.noteProxyOpNoThrow
 12-21 16:19:25.213 12695-12695/? E/dalvikvm: Could not find class 'com.crashlytics.android.ndk.CrashlyticsNdk', referenced from method com.crashlytics.android.CrashlyticsInitProvider.createCrashlyticsKits
 12-21 16:19:25.464 12695-12735/com.myProject.demo E/dalvikvm: Could not find class 'android.os.UserManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtilLight.isRestrictedUserProfile
 12-21 16:19:25.884 12695-12735/com.myProject.demo E/Fabric: Settings request failed.
 12-21 16:19:25.894 12695-12736/com.myProject.demo E/Answers: Failed to retrieve settings

I searched a lot and the only related thing I found was this, which is not solving my problem.

react-native with createSwitchNavigator and createMaterialTopTabNavigator memory leak

$
0
0

Current behaviour

After click login and logout couple of times and waiting on login page there is a memory leak error. This happens switching from createMaterialTopTabNavigator to a createSwitchNavigator page.

With this project the error can be reproduced.

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in TabBar (at MaterialTopTabBar.tsx:92)
    in TabBarTop (at createMaterialTopTabNavigator.tsx:84)
    in Pager (at TabView.tsx:70)
    in RCTView (at TabView.tsx:128)
    in TabView (at createMaterialTopTabNavigator.tsx:136)
    in MaterialTabView (at createTabNavigator.tsx:228)
    in NavigationView (at createNavigator.js:80)
    in Navigator (at SceneView.js:9)

Expected behaviour

Is expected no memory leaks after navigating between switchNavigator and materialTopTabNavigator pages.

Code sample

SignIn

import React from 'react';
import { Text, View, Button } from 'react-native';

// import { Container } from './styles';

export default function Dashboard({ navigation }) {
  return (
    <View style={{ flex: 1, justifyContent: 'center' }}>
      <Text>SignIn</Text>
      <Button title="Login" onPress={() => navigation.navigate('Dashboard')} />
    </View>
  );
}

Dashboard.js

import React from 'react';
import { Text, View, Button } from 'react-native';

// import { Container } from './styles';

export default function Dashboard({ navigation }) {
  return (
    <View style={{ flex: 1, justifyContent: 'center' }}>
      <Text>SignIn</Text>

      <Button
        title="Logout"
        onPress={() => navigation.navigate('SignIn')}
        color="red"
      />
    </View>
  );
}

routes.js

import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';

import SignIn from './pages/SignIn';
import Dashboard from './pages/Dashboard';
import Classroom from './pages/Classroom';
import Student from './pages/Student';

const styleTab = {
  activeTintColor: 'blue',
  labelStyle: {
    fontSize: 20,
  },
  showIcon: false,
  inactiveTintColor: '#DDD',
  style: { elevation: 0 },
  tabStyle: {
    height: 80,
    backgroundColor: '#fff',
  },
  scrollEnabled: true,
  swipeEnabled: true,
  upperCaseLabel: false,
};

const Routes = createAppContainer(
  createSwitchNavigator(
    {
      SignIn,
      App: createMaterialTopTabNavigator({
        Dashboard: {
          screen: Dashboard,
          navigationOptions: {
            tabBarVisible: true,
            tabBarLabel: 'Dashboard',
            tabBarOptions: styleTab,
          },
        },
        Classroom: {
          screen: Classroom,
          navigationOptions: {
            tabBarVisible: true,
            tabBarLabel: 'Classroom',
            tabBarOptions: styleTab,
          },
        },
        Student: {
          screen: Student,
          navigationOptions: {
            tabBarVisible: true,
            tabBarLabel: 'Student',
            tabBarOptions: styleTab,
          },
        },
      }),
    },
    {
      initialRouteName: 'SignIn',
    },
  ),
);

export default Routes;


Screenshots (if applicable)

Login page after error

What have you tried

I have tried some solutions creating a NavigationService and with with navigation focus without success. I may be missing something, in this situations perhaps a simple thing.

Your Environment

  • Android 8.0
  • Ubuntu 18.04 LTS
  • react-navigation "^4.0.10",
  • react-navigation-tabs "^2.6.2"
  • node v10.15.3
  • yarn 1.21.1

What does the react error 'The component for route 'Camera' must be a react component' mean?

$
0
0

When I run my app I get the error: 'The component for route 'Camera' must be a react component'. I do not know what this means:

Here is my App.js:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createAppContainer } from 'react-navigation';
import {createStackNavigator}  from 'react-navigation-stack';
import Home from './screens/Home';
import Camera from './screens/Camera'

const MainNavigator = createStackNavigator(
  {
    Home: {screen: Home},
    Camera: { screen: Camera}
  },
  {
    defaultNavigationOptions: {
      headerTintColor: '#fff',
      headerStyle: {
        backgroundColor: '#b83227'
      },
      headerTitleStyle: {
        color: '#fff'
      }
    }
  }
);

Here is my home:

import React from 'react';
import { StyleSheet, Text, View, Image, Button } from 'react-native';
import Camera from './Camera'
export default class Home extends React.Component{

    static navigationOptions = {
        title: "PhotoClicker"
    }

    render(){

        let photo = this.props.navigation.getParam("Photo", "empty")
        const { navigate } = this.props.navigation;
        return (
            <View style={styles.container}>
                <Image
                    resizeMode="center"
                    style = {styles.imageHolder}
                    source={
                        photo === "empty" ? require("../assets/viking.png") : photo
                    }
                />
                <Button
                title="Take Photo"
                style={styles.button}
                onPress={()=>{
                    this.props.navigation.navigate(Camera)
                }}
                />
            </View>
        );
    }

}

Here is Camera:

import React from 'react';
import { StyleSheet, Text, View, Image, Button } from 'react-native';

export default class Camera extends React.Component{

    render(){
        const { navigate } = this.props.navigation;
        return (
            <View style={styles.container}>
                <Text>Camera Screen</Text>
            </View>
        );
    }

}

It should just be a button that leads from home to Camera, but all I get is the above error. I have tried to change the imports but I just keep getting the same error. Could there be something wrong with my setup, I feel I get many more errors not directly related to code with React-native than I would with Java for Android.

Unable to connect Android emulator to React Native debugger

$
0
0

I am unable to connect android emulator with react native debugger.

When I run react-native run-android, it brings up the app successfully without showing any errors. It also brings up node Metro Bundler as well. But it didn't print any logs in RN debugger. When I press Reload app on the page, it shows the following popup error:

React Native: No apps connected
Sending 'reload' to all React Native apps failed. Make sure your app is running in the simulator or on a phone

Popup error when press on RN debugger "Reload app" button

I tried running this adb reverse tcp:8081 tcp:8081 but it doesn't work. When I press Cmd+m in my emulator, it is showing multi-touch. So I can't open developer menu as well.

unintentional triggered when pressed Cmd+m

System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 60.96 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.12.0 - /usr/local/bin/node
    npm: 6.12.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 27, 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.3/11C29 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: ^0.61.5 => 0.61.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

How can I resolve this?

Custom font not working in React Native

$
0
0

I want to use a font from google fonts in my app. Here is the font.

I have placed the .ttf file in app/fonts.

package.json:

{
    "name": "xxx",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "rnpm": {
        "assets": ["./app/fonts"]
    },
    "jest": {
        "preset": "react-native",
        "moduleNameMapper": {
            "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
            "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
        }
    },
    "dependencies": {
        "flow-typed": "^2.0.0",
        "immutable": "^3.8.1",
        "react": "~15.4.1",
        "react-native": "0.42.0",
        "react-native-vector-icons": "^4.0.0",
        "react-redux": "^5.0.3",
        "redux": "^3.6.0",
        "redux-immutable": "^4.0.0",
        "redux-observable": "^0.14.1",
        "rxjs": "^5.2.0"
    },
    "devDependencies": {
        "babel-eslint": "^7.1.1",
        "babel-jest": "19.0.0",
        "babel-preset-react-native": "1.9.1",
        "eslint": "^3.17.0",
        "eslint-plugin-flowtype": "^2.30.3",
        "eslint-plugin-jsx": "^0.0.2",
        "eslint-plugin-react": "^6.10.0",
        "eslint-plugin-react-native": "^2.3.1",
        "flow-bin": "^0.42.0",
        "jest": "19.0.2",
        "jest-cli": "^19.0.2",
        "react-test-renderer": "~15.4.1",
        "redux-devtools": "^3.3.2",
        "remote-redux-devtools": "^0.5.7"
    }
}

then ran react-native link.

Then use the font in my app:

import { View, Text } from 'react-native'
import React from 'react'
import Width from '../width/Width'
import Shape from '../shape/Shape'
import Height from '../height/Height'
import Thickness from '../thickness/Thickness'

export const Volcalc = () => (
  <View style={styles.container}>
    <Text style={styles.text}>SHAPE</Text>
    <Shape />
    <Text style={styles.text}>HEIGHT</Text>
    <Height />
    <Text style={styles.text}>WIDTH</Text>
    <Width />
    <Text style={styles.text}>THICKNESS</Text>
    <Thickness />
  </View>
)

const $mainColor = '#00d1b2'
const styles = {
  container: {
    flex: 1,
    padding: 20,
    backgroundColor: $mainColor
  },
  text: {
    textAlign: 'center',
    color: 'rgba(255, 255, 255, 0.9)',
    fontSize: 15,
    fontFamily: 'Orbitron'
  }
}

In android it doesn't show the new font but has no error. In ios it has error:

Unrecognised font family "Orbitron"

What am I doing wrong?

How do I find out the EXACT value to place in fontFamily: 'xxx'?


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :react-native-firebase

$
0
0

i'm on Android Studio with an React Native project. Works fine on Xcode but A/S side i get a bunch of errors i'm not familiar with:-

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :react-native-firebase.

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :react-native-firebase.


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :react-native-firebase.


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :react-native-firebase.


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :react-native-firebase.

Assume i need to run the equivalent of an npm install somewhere? Or add in React Native Firebase somewhere? or remove it?

Bizarrely React Native Firebase is NOT in my pkg json dependencies at all. I just use the web api for that - it only exists in Android Studio.

Help?

RNCamera Error:TypeError: CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function

$
0
0

[Unhandled promise rejection: TypeError: CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function. (In 'CameraManager.checkIfRecordAudioPermissionsAreDefined()', 'CameraManager.checkIfRecordAudioPermissionsAreDefined' is undefined)]

return (
  <View>
    <Text>Welcome to React Native QRScanner!</Text>

    <RNCamera
      ref={ref => {
        this.camera = ref;
      }}
      style={{
        flex: 1,
        width: '100%'
      }}
      androidRecordAudioPermissionOptions={{
        title: 'Permission to use audio recording',
        message: 'We need your permission to use your audio',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel',
      }}
      onBarCodeRead={this.barcodeRecognized}
    >

    </RNCamera>
  </View>
);

Adding native icon symbols reacts without Xcode and mac os

$
0
0

I wrote my program with React Native. I did some research on adding icons to the iOS app and found I needed Xcode but couldn't install the Mac for various reasons. Now I want to know if I have any other way to change the iOS app icon?   Thank you for helping me

Error when running expo run on react native app

$
0
0

When i run the app with expo start then after 5 seconds i got blank screen and this error

C:\Users\lp\apps\test\App>expo start
Starting project at C:\Users\lp\apps\test\App
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)


Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class


Metro Bundler process exited with code 1

Read and play sheet music react nativeor kotlin [closed]

$
0
0

I'm trying to write an music notation mobile app and have problem with read notation on app, can I read an music notation like xml file and show in five line (sheet music) and play it? Is it possible to read and play a sheet music (Music notation) with Kotlin or React Native?

Viewing all 30345 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>