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

React Native Crop Image inside of the square

$
0
0

how do I get the picture inside of the square :

Client :

RM: *the white square is located at the fourthLine (<View ref={view => { this.feedPost = view; }} style={[styles.grid]}>) *

<View style={[{flex: 40}, styles.maskFrame]} ></View><View style={{ flexDirection: 'row', width: '100%' }}><View style={styles.marginViewStyle}></View><View ref={view => { this.feedPost = view; }} style={[styles.grid]}></View><View style={styles.marginViewStyle}></View></View><View style={[styles.footer, styles.maskFrame]}><IconButton name="cross" onPress={goBack} /><TouchableOpacity onPress={this.snapPhoto.bind(this)} ><View style={styles.snapButton}><View style={[styles.innerSnapButton, { backgroundColor: theme.palette.primary }]}><Icon color="white" name="camera" /></View></View></TouchableOpacity><IconButton name="flash" onPress={toggleFlash} /></View>

CSS :

    marginViewStyle: {
        backgroundColor: 'rgba(1,1,1,0.6)',
        height: ( width - (StyleGuide.spacing.small * 2) ) * 2 / 3,
        width: '5%',
    },
    grid: {
        alignItems: 'center',
    //    justifyContent: 'space-around',
        top: 0,
        left: 0,
        borderColor: StyleGuide.palette.white,
        borderWidth: 4,
    //    marginLeft: StyleGuide.spacing.small,
        width: '90%',
        height: ( width - (StyleGuide.spacing.small * 2) ) * 2 / 3,
        borderRadius: 5,
    },

enter image description here


Debug JS Remotely not showing up in developer tools option for emulator in Android Stuido

$
0
0

I'm trying to set up react-native-debugger standalone tool. Both metro and the debugger are connected to port 8081 on localhost but they dont seem to be connected to each other. The debugger is stuck on "waiting for client to connect". On top of this, when I open up the dev tools using ctrl+m there is no remote debugging option, only debug, which crashes the application with no error messages to the console. Can anyone tell me what I might be doing wrong?

enter image description here

enter image description here

enter image description here

ScrollToTop works once in a flatListItems [closed]

$
0
0

I have a list of items that each item has an image album in a horizontal scrollView

I want each item to scrollToEnd

But it works only on the last item in the list and all other items are in first image of album

What should I do?

Detect selecting current selectedValue with React-Native Picker

$
0
0

I'm using React-Native's Picker component. Say I have the following:

export class someComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {
            someVal: 1
        };
    }

    onNewValueSelected = (newVal) => {
        Alert.alert('You selected the value: ' + newVal)
        this.setState({someVal: newVal});
    }

    render() {


        return (
            <View style={styles.container}>
                <Picker
                    selectedValue={this.state.someVal}
                    prompt="Select Some Value"
                    onValueChange={this.onNewValueSelected}
                    mode='dropdown'>
                    <Picker.Item label='one' value={1} />
                    <Picker.Item label='two' value={2} />
                    <Picker.Item label='three' value={3} />
                </Picker>
            </View>
        );
    }

}

How would I detect that the currently selected value is selected in the modal? Say when this component first mounts the user selects 1. How would i know that they selected 1? onValueChange does not fire when the selectedValue is selected (at least on Android). I also don't see any way of creating a workaround for this component since I don't know a way of detecting when the Picker's modal or dropdown is opened and dismissed.

Maybe I just need to build a custom button and modal to handle this? Any help is appreciated. Thanks!

Error: spawn cmd ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)

$
0
0

C:\repo\dem1>npm start

@ start C:\repo\dem1 expo start

Starting project at C:\repo\dem1

Expo DevTools is running at http://localhost:19002 Opening DevTools in the browser... (press shift-d to disable) Error: spawn cmd ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)

at onErrorNT (internal/child_process.js:415:16)

at process._tickCallback (internal/process/next_tick.js:63:19)

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @ start: expo start npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ start script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

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?

Can i implement an E2EE on a voice call mobile app react native? [closed]

$
0
0

Am in lost about how and if its possible to implement encryption to my voice call app in react native.

Is encrypting voice in E2EE model for a mobile app is possible? like how about the speed and its a real time data transferring.

What algorithm is better to use if its a good idea to do it? if its not possible (or not a good idea) what do you recommend me to use?

I did a search on internet but there was a lot of fuzzy in what I read as for encrypting voice by signals!?! and there was what I read in some book about stream encrypting too! Should I use it?

The problem is there is no complete guide on internet that shows how to implement and join all the pieces together beside all the articles I read was only give a part of the information then recommend some pre API's that do the whole process of transferring and encrypt the data!

As a note: What I want to do exactly is to build a voice call app in react native using an API for voice transferring but I want (Have to) do the encryption of that voice as its my thesis. So any help by pointing on the way is apricated please. Thanks in advance!

Expo build for Android stuck in queue

$
0
0

I'm trying to build the expo app with expo build:android but it just stuck with the message Build in progress....


assembleRelease on react-native 0.60.6 android to create APK is throwing so many different errors

$
0
0

Whenever I attempt to run:

./gradlew assembleRelease

It throws errors with my assets saying "Duplicate resources". Attempted everything I found in github and also here in Stackoverflow but I couldn't make it work. Even the "fix" modifying the react.gradle in node_modules which I find disgusting.

Also attempted removing all my assets before running assembleRelease:

rm -rf ./android/app/src/main/res/drawable-*

rm -rf ./android/app/src/main/res/raw

But when I do the workaround above, instead of throwing the errors related to assets, it throws errors related to BuildTypes for every dependency that I'm using:

Unable to find a matching variant of project :@react-native-community_blur:
          - Variant 'debugApiElements' capability MyApp:@react-native-community_blur:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'packagingOptions' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Required RNN.reactNativeVersion 'reactNative60' but no value provided.
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
          - Variant 'debugRuntimeElements' capability MyApp:@react-native-community_blur:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'packagingOptions' and found incompatible value 'debug'.
              - Other attributes:
                  - Required RNN.reactNativeVersion 'reactNative60' but no value provided.
                  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'releaseApiElements' capability MyApp:@react-native-community_blur:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'packagingOptions' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:

(assembleDebug works just fine by the way.)

I'm using RN 0.60.6 & Gradle 5.6.1

Nothing works so far. Any ideas? It's literally driving me nuts.

React-native Pushy notification in Android

$
0
0

I have implemented pushy notification in my react-native project following below link: https://pushy.me/docs/additional-platforms/react-native

I am facing problem on Android, I am getting the notification but on clicking on notification from the notification bar, I am not getting any callback or control on react-native method => Pushy.setNotificationListener

According to documentation, we have to get the call in Pushy.setNotificationListener method.

Please let us know how to proceed in this as soon as possible.

How can i regenerate ios and android folder?

$
0
0

How can I regenerate ios and android folder in React Native project?

react-native-cli: 2.0.1 react-native: 0.61.2

❯ react-native eject error Unrecognized command "eject". info Run "react-native --help" to see a list of all available commands.

❯ react-native upgrade --legacy true error: unknown option `--legacy'

React Native - How to create URL scheme for my application?

$
0
0

I want to redirect the user from my website to my application. I explore this documentation but I am failed to know how to create a link or deep link for my application that will redirect the user to my application and this link will be understood by the application.

Can anyone tell me a little bit about the linking and deep linking and also teach me the steps how to create a link or deep link for my app? What is the process & method of creating the URL scheme for your application? I don't have any background in Java or Objective-C. Thanks !!!

Travis CI build fails on react-native android

$
0
0

I am trying to build my react-native project with travis ci using this command:

script: 
    - npm install -g npx && cd android && sudo chmod +x gradlew && sudo ./gradlew assembleRelease#3

However, my build fails with the following error: Cannot run program "npx": error=2, No such file or directory

My full config if as follows:

language: android
before_install: #1.1
- nvm install 10
- node --version
install: #1.2
- npm install
android: #1.3
  components:
  - build-tools-23.0.1
  - android-23
  - extra-android-m2repository
  - extra-google-google_play_services
  - extra-google-m2repository
  - addon-google_apis-google-16
script: 
    - npm install -g npx && cd android && sudo chmod +x gradlew && sudo ./gradlew assembleRelease#3
deploy: # mostly generated by `> travis deploy releases`
  skip_cleanup: true

It seems as though the build file is unable to find npx even though I have installed globally with npm. In the native_modules.gradle files where the errors, the error line is as follows:

def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx"

Here is a call stack where the error occurs:

Welcome to Gradle 5.5!
1776
1777
Here are the highlights of this release:
1778
 - Kickstart Gradle plugin development with gradle init
1779
 - Distribute organization-wide Gradle properties in custom Gradle distributions
1780
 - Transform dependency artifacts on resolution
1781
1782
For more details see https://docs.gradle.org/5.5/release-notes.html
1783
1784
Starting a Gradle Daemon (subsequent builds will be faster)
1785
1786
1787
> Starting Daemon<-------------> 0% INITIALIZING [21ms]<-------------> 0% INITIALIZING [121ms]> Evaluating settings<-------------> 0% INITIALIZING [221ms]<-------------> 0% INITIALIZING [321ms]<-------------> 0% INITIALIZING [421ms]<-------------> 0% INITIALIZING [521ms]<-------------> 0% INITIALIZING [621ms]<-------------> 0% INITIALIZING [721ms]<-------------> 0% INITIALIZING [822ms]> Evaluating settings > Compiling /home/travis/build/daniel-sudz/bbox-mobile/an<-------------> 0% INITIALIZING [921ms]<-------------> 0% INITIALIZING [1s]> Evaluating settings> Evaluating settings > Compiling /home/travis/build/daniel-sudz/bbox-mobile/no> Evaluating settingsmand from 'null' directory failed.
1788
1789
FAILURE: Build failed with an exception.
1790
1791
* Where:
1792
Script '/home/travis/build/daniel-sudz/bbox-mobile/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 154
1793
1794
* What went wrong:
1795
A problem occurred evaluating script.
1796
> Cannot run program "npx": error=2, No such file or directory

Note: the build occurs on ubuntu

Any ideas on what the solution may be?

React Native - Disable "Screen Size" Setting

$
0
0

I am currently developing a React Native application, and some of our users might have slight vision problems. We wish to prevent the setting "Display Size" in Android, as this makes our app unusable.

We solved the problem with the Font Size using the simple line:

Text.defaultProps.allowFontScaling=false;

Is there a similar solution to the Display Size setting?

Thanks in advance

Can not send request when screen is locked

$
0
0

My React Native (Android) application sends requests to the server when some events are triggered. But when I lock phone screen and in a few minutes event is triggered, app try to send request, but it fails. I tried fetch (error Network request failed) and XMLHttpRequest.

On some devices it works fine and I can't understand it depends on Android version or on device model.

Why does it happen and why on some (not all) devices? How can I fix it? Thanks!


react-native: Android project on Linux won't compile due to package androidx.transition not existing

$
0
0

I'm building a react-native 0.61 application for Android. On my mac everything has always worked fine, now I'm trying to install the same environment in a Linux (kubuntu 19) laptop. I went to the official guide, installed react native cli, java, android studio and everything I needed.

When I try to lunch the project through react-native run-android I get the following error:

mypath/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java:3: error: package androidx.transition does not exist

I have already tried to install Jetifier and running npx jetify, I get this output:

Jetifier found 1049 file(s) to forward-jetify. Using 4 workers...

but nothing changed...how can I fix this?

React Native | Failed to install the app. Please accept all necessary SDK licenses using SDK Manager

$
0
0

I was trying to start running my react native project. But I'm getting this error while running the react-native run-android command. I tried a bunch of solutions that I found online but neither of them worked.


info Starting JS server...
info Installing the app...

> Configure project :app
Checking the license for package Android SDK Build-Tools 28.0.3 in /home/dipanshuchaubey/Android/Sdk/licenses
Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
Checking the license for package Android SDK Platform 28 in /home/dipanshuchaubey/Android/Sdk/licenses
Warning: License for package Android SDK Platform 28 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;28.0.3 Android SDK Build-Tools 28.0.3
     platforms;android-28 Android SDK Platform 28
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: /home/dipanshuchaubey/Android/Sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

error Failed to install the app. Please accept all necessary SDK licenses using SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses". Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;28.0.3 Android SDK Build-Tools 28.0.3
     platforms;android-28 Android SDK Platform 28
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: /home/dipanshuchaubey/Android/Sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

at checkExecSyncError (child_process.js:616:11)
at execFileSync (child_process.js:634:15)
at runOnAllDevices (/home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39)
at buildAndRun (/home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:137:41)
at /home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:103:12
at processTicksAndRejections (internal/process/task_queues.js:89:5)
at async Command.handleAction (/home/dipanshuchaubey/Documents/practice/native/node_modules/react-native/node_modules/@react-native-community/cli/build/cliEntry.js:160:7)

How to fix this.

Thank you in Advance :)

Socket IO with React Native and Headless JS, can't kill it

$
0
0

This is mi first post so I will try to show my problem in a clear way and I'm not an android developer with a basic kownledge of java.

I'm trying to run a socket IO client in my react-native app, as I inquire in order to achieve this I use Headless JS task to have this socket running in the background and even when the app is close, the user recieves a notification.

I have all the flow working well, but the only problem is that when I execute Background.stopService(), the websocket do not disconect but the persistance notification disappear.

index.js (where I register the task)

const MyHeadlessTask = async () => {
  const email = await AsyncStorage.getItem('email');

  if (!!email) {
    try {
      let socket = SocketIOClient('url', {
        transports: ['websocket'],
        query: `email=${email}`
      });

      etc...
    } catch (ex) {
      console.log('[MyHeadlessTask() ex] ', ex)
    }
  }
};

AppRegistry.registerHeadlessTask('Background', () => MyHeadlessTask);

BackgroundEventService.java

public class BackgroundEventService extends HeadlessJsTaskService {
  @Nullable
  protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    WritableMap data = extras != null ? Arguments.fromBundle(extras) : Arguments.createMap();

    return new HeadlessJsTaskConfig(
      "Background",
      data,
      5000,
      true
    );
  }
}

BackgroundModule.java

public class BackgroundModule extends ReactContextBaseJavaModule {

  public static final String REACT_CLASS = "Background";
  private static ReactApplicationContext reactContext;

  public BackgroundModule(@Nonnull ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Nonnull
  @Override
  public String getName() {
    return REACT_CLASS;
  }

  @ReactMethod
  public void startService() {
    this.reactContext.startService(new Intent(this.reactContext, BackgroundService.class));
  }

  @ReactMethod
  public void stopService() {
    this.reactContext.stopService(new Intent(this.reactContext, BackgroundService.class));
  }
}

BackgroundPackage.java

public class BackgroundPackage implements ReactPackage {

  @Override
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    return Arrays.<NativeModule>asList(
      new BackgroundModule(reactContext)
    );
  }

  @Override
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Collections.emptyList();
  }
}

MainApplication.java (add package)

@Override
      protected List<ReactPackage> getPackages() {
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
        // Packages that cannot be autolinked yet can be added manually here, for example:
        // packages.add(new MyReactNativePackage());
        packages.add(new BackgroundPackage());
        return packages;
      }

and this are the two ways that I writed BackgroundService.javafirst one

public class BackgroundService extends Service {

  private static final int SERVICE_NOTIFICATION_ID = 12345;
  private static final String CHANNEL_ID = "BACKGROUND";

  private Handler handler = new Handler();
  private Runnable runnableCode = new Runnable() {
    @Override
    public void run() {
      Context context = getApplicationContext();
      Intent myIntent = new Intent(context, BackgroundEventService.class);
      context.startService(myIntent);
      HeadlessJsTaskService.acquireWakeLockNow(context);
      //handler.postDelayed(this, 2000);
    }
  };
  private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      int importance = NotificationManager.IMPORTANCE_DEFAULT;
      NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "BACKGROUND", importance);
      channel.setDescription("CHANEL DESCRIPTION");
      NotificationManager notificationManager = getSystemService(NotificationManager.class);
      notificationManager.createNotificationChannel(channel);
    }
  }

  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }

  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    this.handler.removeCallbacks(this.runnableCode);
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    this.handler.post(this.runnableCode);
    createNotificationChannel();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
      .setContentTitle("Safe Home")
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentIntent(contentIntent)
      .setOngoing(true)
      .setPriority(NotificationCompat.PRIORITY_MIN)
      .setVisibility(Notification.VISIBILITY_SECRET)
      .build();
    startForeground(SERVICE_NOTIFICATION_ID, notification);
    return START_STICKY;
  }

}

second one

public class BackgroundService extends Service {

  private static final int SERVICE_NOTIFICATION_ID = 12345;
  private static final String CHANNEL_ID = "BACKGROUND";
  private volatile boolean running = true;

  private Thread thread;
  private Runnable runnableCode = new Runnable() {
    @Override
    public void run() {
      if (running) {
        Context context = getApplicationContext();
        Intent myIntent = new Intent(context, BackgroundEventService.class);
        context.startService(myIntent);
        HeadlessJsTaskService.acquireWakeLockNow(context);
      } else {
        Context context = getApplicationContext();
        Intent myIntent = new Intent(context, BackgroundEventService.class);
        context.stopService(myIntent);
      }
    }
  };
  private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      int importance = NotificationManager.IMPORTANCE_DEFAULT;
      NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "BACKGROUND", importance);
      channel.setDescription("CHANEL DESCRIPTION");
      NotificationManager notificationManager = getSystemService(NotificationManager.class);
      notificationManager.createNotificationChannel(channel);
    }
  }

  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }

  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
  public void onDestroy() {
    running = false;
    this.thread.interrupt();
    super.onDestroy();
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    this.thread = new Thread(this.runnableCode);
    this.thread.start();
    createNotificationChannel();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
      .setContentTitle("Safe Home")
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentIntent(contentIntent)
      .setOngoing(true)
      .setPriority(NotificationCompat.PRIORITY_MIN)
      .setVisibility(Notification.VISIBILITY_SECRET)
      .build();
    startForeground(SERVICE_NOTIFICATION_ID, notification);
    return START_STICKY;
  }

}

This problem is giving me a headache, and I can't find a solution, I repeat everthing works well but it seems that the BackgroundEventService don't stop and the sockets still running, I try too many ways to stop the thread but nothing works for me. Maybe i'm using wrongs concepts or the is an error in my code...

How to view the changes of an imported file in React-Native?

$
0
0

I have a .js file that stores several json objects that will be used to dynamically create components in various parts of the app. For ex:

import langUtil from '../utilities/langUtil';
export default {
 ...
    DEFAULT_DAY_TIME: {
        "times": [
            {
                "name":langUtil.day_morning,
                "value":"1"
            },
            {
                "name":langUtil.day_afternoon,
                "value":"2"
            },
            {
                "name":langUtil.day_evening,
                "value":"3"
            }
        ],
    ...
}

langUtil uses the 'react-native-localization' package to give translations in various languages. Therefore, if the language is currently set to be English, it will show the text as "Morning" and if its French, "Matin" and so on. This actually works with no issue if I use langUtil.day_morning inside a component:

<Text>{langUtil.day_morning}</Text> //will show the correct language when language is changed

Because my app has an option to change language, I would like it to update all the text to the new language, and as mentioned, this works for when langUtil is used inside a component.

However, if I do this in render:

render() {
    const { DEFAULT_DAY_TIME} = json_constants;

and json_constants is imported like this:

import json_constants from '../../assets/json_constants';

It will not update when the text upon language change. I assume its because its already been imported and the language has already been set. So it will not re-import the file. I'm wondering if there is a way to change the language for those objects, or do I need to rethink the whole setup?

By the way, here is a simplified example of how those objects are used:

{DEFAULT_DAY_TIME.map(item => {
        return (
                <View key={item.value} style={styles.label} >
                        <Text>{item.name}</Text>
                </View>
        );
})}

Reading data from BLE espruino based device

$
0
0

I am approaching for the first time the development of an application which should read the data printed by a BLE (espruino based) device. Using this open source android application https://github.com/kai-morich/SimpleBluetoothLeTerminal I am able to see what the device prints on the console. I would like to accomplish the same thing on my RN based application, reading the data it prints and eventually printing on screen the values it reads. I managed (with the polidea library https://polidea.github.io/react-native-ble-plx/#blemanagerreadcharacteristicfordevice) to connect the device and am looking into the characteristics, but I can't figure out how to read this. Anyone has useful documentation regading this issue? Thank you

Viewing all 28479 articles
Browse latest View live


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