Malformed calls from JS : field sizes are different - react-native

I've gone through link : https://github.com/facebook/react-native/issues/23835#issuecomment-493007479
But got no solution. I got the understanding that this bug is triggered when
You send NaN in array on react native bridge. I don't know much about it.
During use of invalid data (infinity) in animation.
During bottom navigation.
Using menu.
Showing response data in Alert or Notifications as Toasts.
I am using react-native-ble-manager.
Procedure: I sent write message using characteristic that allows write, after setting notifications on for characteristic that allows read. I got 'ack' in the response listener that was used to receive notifications, and then I start sending custom data chunks by chunks as designed.
I get this error during this first chunk was being sent.
I've checked my uint8Array for any wrong data using iteration and to, but couldn't found any.
From my logs:
2020-09-04 12:52:13.944 21942-22004/com.my_app E/ReactNativeJS: Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.
[[3,13,37],[5,22,0],[["{\"type\":\"log\",\"level\":\"log\",\"data\":[\"payload[18]: \\u0000\"]}",1],[221,100,1599204133919,false]],2453]

I iterated through my uint8Array and took each of the elements in
var newArr = [];
I also did newArr[i] = newArr[i] & 0xff.
The error was gone.

Related

Persistent React-Native error that goes away with Remote Debugging enabled

I'm building a React-Native app and whenever I run it on my Android emulator, I get this error:
Objects are not valid as a React child (found: object with keys
{$$typeof, type, key, ref, props, _owner, _store}). If you meant to
render a collection of children, use an array instead.
throwOnInvalidObjectType
D:\rn\manager\node_modules\react-native\Libraries\Renderer\ReactNativeRenderer-dev.js:7436:6
Because this error means nothing to me, I decide to enable "Debug JS Remotely" in Chrome to see if I can get an error I understand. But with Debug Remotely enabled, the error goes away.
If I build the project and install the app on a real device, the errors come back.
But I feel like I'm stuck in a catch-22 because if I try to debug, I get no errors, and if I turn off debugging, I get errors.
Is there anyway to get around this?
Thanks!
The error mentions you use an object in your render() method where you shouldn't. Since you did not post any code, here is what you could do:
Keep removing elements from your render() method until you no longer get the error. Once it is gone, start placing code back until you hit the error again. The code causing the error will be or return an object, possibly a typo causing an object to be returned instead of a string for instance.
TL;DR: Stopped using firebase and used react-native-firebase instead
The problem for me wasn't the render method in any of my components or classes. I realized after trying the answer above, I basically removed all my files, and was left with one file. I changed the render method to display text inside one view, but I still got the error.
Then I started removing the modules I was importing inside that file one by one and found that it was the firebase module uninstalled firebase and installed react-native-firebase.

Send WhatsApp messages automatically with Automate-App

I want to send a WhatsApp message to a specific contact with the Automate-app. How can do I do this?
This is the link to the app:
https://play.google.com/store/apps/details?id=com.llamalab.automate
I know this is pretty late reply.
You can make use of below blocks and build
App start block and choose activity class as
com.whatsapp.ContactPicker
Use Interact blocks for searching, selecting and messaging
Extend with Variable for searching contact and for message text
I have been trying different ways but many of them fall short of full automation.
currently, I am using blocks to send a message to (unsaved) contact. This skips the contactPicker window.
the flow blocks:
[start flow] --> [view content] --> [interact]
that's it!
in view content, you will need to specify the content uri (change number and msg):
https://api.whatsapp.com/send?phone=+966xxxxxxxxx&text=msg
in interact block, specify the (proceed) when element appeared.
the (action) is click.
and (XPATH):
fn:reverse((.//[{("android.widget.ImageButton") = null ? "true()" : "fn:choose(#class,string(#class),name())={"android.widget.ImageButton";xpathEncode}"} and {("com.whatsapp:id/send") = null ? "true()" : "#android:id={"#" ++ ("com.whatsapp:id/send");xpathEncode}"}])[1]/ancestor-or-self::)
that's it.

Confusing Swift type annotations for React Native Promises

I'm playing around with React Native and attempting to write some native code that communicates over bluetooth. I'm confused by the type annotations that I need to use in order for it to work. Could someone please explain why I have to have the "resolver" and "rejecter" bits in the following two code snippets? Is there a way to write this without those unused parts?
My implementation, MyAsyncModule.swift:
#objc(MyAsyncModule)
class MyAsyncModule: NSObject {
#objc func echoAsync(
input: NSNumber,
resolver resolve: RCTPromiseResolveBlock,
rejecter reject: RCTPromiseRejectBlock
) -> Void {
resolve(input)
}
}
From my bridge file, MyAsyncModuleBridge.m
RCT_EXTERN_METHOD(echoAsync:
(nonnull NSNumber *)input
resolver:(RCTPromiseResolveBlock *)resolve
rejecter:(RCTPromiseRejectBlock *)reject
)
I am coming from scripting land so types are foreign to me, but it seems too weird that React Native refuses to identify my the echoAsync method unless both the implementation and the bridge include the resolver and rejecter bits...
The resolver and reject calls are needed to have the framework generate a "promise". A promise can be thought of as a placeholder for a value that will be made available in the future. The resolver is called when the native code is done doing its work and is ready to pass the results back to the JavaScript land. reject is used when the native side detects an error and is used to report that error from native to JavaScript land.
To get a bit deeper, when you're JavaScript calls a native function, it doesn't pause and wait for native to finish up like a normal function call. It instead just goes on executing the next line of code (notice how React-Native prevents you from setting a return value for your exported functions meaning they are explicitly making sure you don't try and wait for a return value).
So then how does native code ever report the results back to JavaScript? There are two options
callbacks (in native these have the type RCTResponseSenderBlock) when called, cause a JavaScript function to run with the passed arguments
promises (with the types RCTPromiseResolveBlock and RCTPromiseRejectBlock) which causes you success handler to run with the passed arguments when resolver is called or causes your error handler to run when reject is called.
As for async function you MUST use promises.
For more info on JavaScript promises checkout:
http://www.html5rocks.com/en/tutorials/es6/promises/
https://facebook.github.io/react-native/docs/native-modules-ios.html#promises

"Invalid cross-thread access" when changing a WP8 textBlock

I'm coming from VB 6 and am semi-new to VB.NET.
I'm writing a Windows Phone 8 application. There's a grid in which I have several textBlocks that I want to dynamically display data from a file stream (that contains scanned data).
When the WP8 page opens, it automatically loads the data into the textBlocks. This works. Before I load the data from the file, I want to "reset" all textBlocks and hide them. For this I wanted to use a procedure which essentially does the following for every textBlock:
tbl1.Text = ""
tbl1.Visibility = System.Windows.Visibility.Collapsed
This works exactly one time: when the page loads. The procedure does not produce an error.
Now when I call that method again later, when I want to refresh the data shown on the page, I get the following error on the first line of code shown above:
An exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll but was not handled in user code
Additional information: Invalid cross-thread access.
I'm a bit lost now. In VB6 I was able to do whatever I wanted with my UI elements. I presume I'm making some kind of newbie mistake here?
I read somewhere about some Dispatcher thing. But that seems overly complicated to simply change a value in a textBlock to me. Is there no simple way?
The solution is indeed to use the Dispatcher.BeginInvoke method.
Dispatcher.BeginInvoke(() =>
{
tbl1.Text = ""
tbl1.Visibility = System.Windows.Visibility.Collapsed
});
The reason why you need this is because you try to access an object that depends on the UI thread from a non-UI thread.
It is probably because you are not calling the method from UI thread. Try using Dispatcher.BeginInvoke:
Dispatcher.BeginInvoke(()=>
{
tbl1.Text = "";
tbl1.Visibility = System.Windows.Visibility.Collapsed;
});

How to know if QLPreviewController successfully loaded a document/failed to load it?

My iOS app loads a variety of documents using QLPreviewController. My aim is to set a flag if the document loaded properly and show an error if it didn't.
Curiously the QLPreviewControllerDelegate protocol offers no callback to check this, nor does the QLPreviewController seem to throw any exception when I try to load an invalid file.
For the record, I tried loading an invalid PDF and it simply logged a message about not being able to find the header and displayed an empty file.
Can anyone please tell me how I can figure this out?
Thanks!
If establishing whether an item could be displayed beforehand works for you then a call to the following may be an option:
+(BOOL)canPreviewItem:(id<QLPreviewItem>) item