I just installed React Native, and am attempting to follow tutorials on the React Native website to get accustomed to it. However every tutorial I end up doing just gives me a big red error screen in the iOS Simulator.
As an example, I followed the "Hello World" tutorial on the React Native website
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class HelloWorldApp extends Component {
render() {
return (
<Text>Hello world!</Text>
);
}
}
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
but am met with this error after compiling and running in the simulator"
"Application TestProject has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent"
I'm confused because I know nothing yet about RN, am following their tutorials to the letter, and am getting errors.
Please advise?
There might be two possibilities as I know of:
When you run react-native run-ios the packager didn't start automatically. If that's the case, Run the Packager Manually. To do so:
In one Tab of your terminal run react-native start and in another run react-native run-ios.
Or while following the document from react native's site, you might have changed the app's name. Like:
You created a project using react-native init AwesomeProject. The Project's name here is AwesomeProject.
And then changed your default index.ios.js and replaced the Component's name with HelloWorldApp.
class HelloWorldApp extends Component
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
Related
I'm using Expo's iOS simulator with my React Native app. Before, it would live update / "fast refresh" when code changes were made, but it's no longer doing that. So this is not about using the Expo Go app on my phone, but rather the Simulator on my Macbook.
I've checked the shake (ctrl + cmd + Z) menu, and Fast Refresh is still enabled. Running npx expo run:ios does correctly reflect the latest code, but that takes a while to run.
Any help to debug this?
A few days ago the same thing happened to me and it depended on how I exported the main component to App.tsx.
This one doesn't work properly:
export default () => {
return <View/>
}
This one works:
const App = () => {
return <View/>
}
export default App
Let me know if this helps
I have a React Native app with a custom native plugin.
The app works fine when I test it with Xcode on my device.
I uploaded the exact same app to the App Store and it got broken.
On my iPhone it doesn't actually start and on my iPad it is buggy:
I have to tap buttons twice
Code order is wrong (may threading / rendering)
Events from the plugin sometimes get fired and sometimes not. Totally random. (could also be rendering issue)
Unfortunately, I can't debug the TestFlight App.
Does someone have a starting point why this could happen?
I found the problem. It was in my Plugin and how I expose it. My index.ts file looked like this:
import { NativeModules } from 'react-native';
const { MyPlugin } = NativeModules;
export default MyPlugin;
Better with no default export:
import { NativeModules } from 'react-native';
export const { MyPlugin } = NativeModules;
I don't know why a default export doesn't work in release mode. I tried all release flags to be the same as default, but it was the same result.
So, just changing the way of export was fixing it.
I have created a flutter app using Android Studio and am adding some code to implement the social media share function using this package [https://pub.dartlang.org/packages/share].
I modified the code so the share function is called each time the floating button is tapped/clicked.
I added share: ^0.5.3 to pub spec.yaml and import the package. I added a line to the increment counter function as follows
`
void _incrementCounter() {
Share.share('check out my website https://example.com');
setState(() {
_counter++;
});
`
Everything runs fine until I press the button and then I get the following exception:
VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)
Any help appreciated :)
It seems that these problems are caused by the new build system Apple introduced in Xcode 10. There is more info here github.com/flutter/flutter/issues/20685#issuecomment-421511890
I have changed from the beta channel to the master channel and now have the example code provided by the Share package authors running in the simulator and on a device.
As my title says, I created a bare bones iOS native module in react native and it is not appearing in the final NativeModules javascript object. Here's exactly what I'm doing. I'm pretty stumped by this.
Create fresh project with react-native init testproj
Open ios folder of testproj in xcode and create a Cocoa Touch Class called MyModule
In MyModule.h I have the following:
#import <React/RCTBridgeModule.h>
#interface MyModule : NSObject <RCTBridgeModule>
#end
In MyModule.m I have the following:
#import "MyModule.h"
#implementation MyModule
RCT_EXPORT_MODULE()
#end
I run react-native run-ios and the app builds successfully. When printing out the NativeModules like so:
import React, {Component} from 'react';
import {NativeModules} from 'react-native'
export default class App extends Component {
componentWillMount() {
console.log('my modules! ', NativeModules)
}
render() {
...
}
}
I don't see MyModule in the console logs but I see all of the base react native modules.
Does anyone have any ideas as to why this would happen? Is there something I'm missing in the xcode build phase? For more context, these are the relevant versions:
xcode 9.4.1
react 16.4.0
react-native 0.55.4
Running on iPhone 6 - 11.4 simulator
React Native will not expose your native module if it doesn't have any methods.
You need to export at least one method using the RCT_EXPORT_METHOD (or RCT_REMAP_METHOD) macro before you will be able to access it.
I have tried following documentation here http://ionicframework.com/docs/v2/native/device/ but am not getting anything back.
home.ts
import {Component} from '#angular/core';
import {Device} from 'ionic-native';
#Component({
templateUrl: 'build/pages/home/home.html',
})
export class HomePage {
public device;
constructor() {
this.device = {};
platform.ready().then(() => {
this.device['uuid'] = Device.device.uuid;
});
}
}
home.html
<li>Device UUID is {{device.uuid}}</li>
I have already ran ionic plugin add cordova-plugin-device
UPDATE: i am testing the app using IonicView App.
Debugging in the Chrome Debugger under different device sizes will not allow you to debug any type of code related to native device properties, hence you need to test your app through an emulator (ios/ android). Please note ionic serve allows you to view the app through the default browser application which isn't an emulator.
For reference on how to test your app through ionic on an emulator see the CLI Docs