React Native - 'target. value not working on mobile' - arrays

Greetings fellow humans,
I have a small problem with this little app that is just supposed to store and display data: https://snack.expo.dev/#vevlex/nullnotanobject
When I test this dircetly from my pc (I scan the QR code in my cmd window) on an ipad, the app boots fine but the data is not saved when re-running the app or when sending a job to another window (The "To Do" button on the right that shows up after you check a job).
When I run it from Expo, I get this error: null is not an object (evaluating 'jobs.map'
So I assume I'm doing something wrong with the saving / loading, or when actually writing the map, but I'm not sure, and I don't know how to approach this problem on my own.
Can anyone help me?
Please and thank you.
Update: var temp1 is not being set, as the alert here returns "Unidentified" even tho I just define it in the previous line. This only happens on iOS and android, it works fine on the web sim. Can anyone explain this?
<TextInput
style={s.jobInput}
onChange={(e) => {
var temp1 = e.target.value;
alert(temp1)
setJobs((currentJobs) =>
produce(currentJobs, (v) => {
v[index].address = temp1;
})
);
saveItem();
}}
value={j.address}
placeholder="Address"
/>

Ok after finding out what I stated in the update I searched a bit more and found out that on mobile you should use onChangeText rather than just onChange.

Related

React native axios crashing and werid behaviour

Axios is behaving weird on my react native webview if you have any idea how to solve or how i can track the problem it would be of much help.
On the onMessage of the webview i recieve the html of the website so i can get a specific link. I send the message when the user taps anywhere on screen.
Injected js:
var body_of_html = document.body;
body_of_html.addEventListener('click',function(e){
window.ReactNativeWebView.postMessage(document.documentElement.innerHTML)
},false);
Case 1
This doesnt console.log anything and after some time crashes the app.
onMessage={event => {
// console.log('asdas');
var regex = new RegExp('token=[a-zA-z0-9]+');
if (event.nativeEvent.data.toString().match(regex) != null) {
let asd =
'https://fvs.io/redirector?' +
event.nativeEvent.data.toString().match(regex);
axios.get(asd).then(rs => {
console.log(rs);
});
Case 2
This one works perfectly fine and logs "Anything".
onMessage={event => {
var regex = new RegExp('token=[a-zA-z0-9]+');
if (event.nativeEvent.data.toString().match(regex) != null) {
let asd =
'https://fvs.io/redirector?' +
event.nativeEvent.data.toString().match(regex);
axios.get(asd).then(console.log("Anything"));
As you can see from the above cases i am unable to get the response from the axios call. Which always after some time crashes the app. Am i doing something wrong on reciving the response ?
Edit: I think I know what might have caused my application to crash but this is just what I found after looking at the data consumed. The link i was sending to the axios.get was retriving bits of a video until it fully buffered. But the way my code was , it would do this action each time i tapped the screen. I guess at some point axios couldnt handle reciving 10x + videos at 1080p at the same time. Just to clarify my intention was just to get the redirection link i didnt know it would cause the video to buffer.
As in all promises, in order to debug the error, e.g. in cases where event.nativeEvent.data may be undefined, causing .toString() to throw error, use a catch block.
axios.get(asd).then(rs => {
console.log(rs);
}).catch(error => console.log("error from axios", error))

analytics().logEvent() return null and not tracking the event in console

I want to use firebase analytics in react native. I have added the lib,
but when i use the await analytics().logEvent("event_name") it returns null and event is also not added in firebase analytic console.
Any one have any idea what's wrong?
<Button
title="Add To Basket"
onPress={async () =>
await analytics().logEvent('basket', {
id: 3745092,
item: 'mens grey t-shirt',
description: ['round neck', 'long sleeved'],
size: 'L',
})
}
/>
I had the same issue when I started with analytics.
Firebase says it takes around 24 hours for the events to be visible on console.
Also the logEvent has a return type of void, hence you see null being returned. So don't worry regarding that aspect unless you have an error.
So, I would suggest you to wait for the changes to be reflected.
For Development purposes we would need to see Realtime events, and Firebase has DebugView for that. For details, refer this document:
https://firebase.google.com/docs/analytics/debugview

ReactJS DropDown and PhantonJS Headless not playing nice together

Good day all,
I'm currently trying to run cucumber tests on a reactjs component, dropdown search selection, running in headless mode, using PhantonJS, but it is causing a weird situation that preventing me from completely these tests.
Using the following reactJs dropdown, http://jedwatson.github.io/react-select/, it is the "'Github users (Async with fetch.js)'"
The current issue that is according is when the scenarios gets to it fourth example test it fails but the same code is used to pass the first three tests.
I thought it was the fourth example so I changed it around with other values and it still fails on the fourth step.
This is the code used to enter the value into the drop down search
find(".Select").trigger("click")
fix_overlap = %{ $('.Select-placeholder').css('z-index', -99999) }
page.execute_script(fix_overlap)
find(".Select .Select-input input").native.send_keys(with)
find(".Select-menu-outer", text: with, visible: :all, match: :first).click
The react control is doing async call to search for the input data from an API endpoint.
I able to run the test in a browser with no issues.
The error that is being returned from the test is that I can't found the value in the drop down.
I have added the options to the environment setup when I'm registering poltergeist,
options = {:js_errors => false, phantomjs_options: ['--debug=true'], debug: false }
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, options)
end
to see if there is an internal error that is not shown in the debug console.
I have done a page.save_screenshot to see the state just before the error and the drop down has the correct value.
Questions
Is there any other options that can be added to show more information/errors?
Has anyone experienced this issue before?
I'm open to any suggestions to fix this weird behaviour.
Extra details
gem 'poltergeist','= 1.9.0'
gem 'cucumber', '~> 2.0'
For the "Cities (Large Dataset)" example on the linked page, the following code selects the "New York" entry for me, without resorting to using trigger, execute_script or native
with = "New York"
section = find('.section', text: 'Cities (Large Dataset)')
section.find('.Select').click
section.find('.Select-placeholder').send_keys(with)
section.find('.VirtualizedSelectOption', exact_text: with).click
That is using the latest Poltergeist and Capybara. Without the latest Capybara you'd probably need to pass a regex as a :text option in the last line rather than the :exact_text option (otherwise you will get multiple respones)
For the "Contributors (Async)" example
with = 'Craig Dallimore'
section = sess.find('.section', text: 'Contributors (Async)')
section.find('.Select').click
section.find('.Select-input input').send_keys(with.gsub(' ', '')
section.find('.Select-option', exact_text: with).click
will select someone

NancyFx will not display images

My last attempt: Don't even know what I'm doing anymore:
Get["/{any}/x.png"] = x => {
return Response.AsImage(Program.portal.ourRoot + "x.png");
};
Get["/{any}/{moreany}/x.png"] = x => {
return Response.AsImage(Program.portal.ourRoot + "x.png");
};
Get["/{any}/{moreany}/{extraany}/x.png"] = x => {
return Response.AsImage(Program.portal.ourRoot + "x.png");
};
What I currently have in my ConfigureConvetions (in the BootStrapper). I've tried a lot of permutations so far.
protected override void ConfigureConventions(NancyConventions conventions) {
//conventions.StaticContentsConventions.AddFile("x.png", ourRoot + "x.png");
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddFile("/portal/images/x.png", ourRoot + "x.png"));
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("images", ourRoot, new string[] { "png" }));
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/portal/", ourRoot, new string[] { "png" }));
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/", ourRoot, new string[] { "png" }));
base.ConfigureConventions(conventions);
}
I have a CustomRootPathProvider that points to ourRoot (string, currently holds a direct C:\somepathstuffhere\ to a content directory).
I only need to serve a single image for my needs (at least, for now, things always tend to grow). I'm using the directory structure as variables, so I need to be able to serve this image from a very large amount of locations.
I have a copy of the image in my root folder, and in a directory called images (the "images" has had '/''s all over it, occasionally even through the middle). I am currently referencing the image with "/images/x.png", but I've tried from the root, just the name, and "images/x.png".
Thanks!
I will post back in the mean time if I figure it out (I'm assuming its something very simple.)
Solved: Worked Around? \ Non-Optimal
I changed my /images/x.png references to 'x.png', and then I dropped the extension reference to the following line.
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/", ourRoot));
Nancy started catching the 'x.png' image for the Root Page and the \Portal\ page. And then the 2nd Get /{any}/{moreany}/x.png started catching the rest of the 'x.png' requests (\Portal\Project).
I'm really not sure, why it started working all of a sudden. I've just been playing the permutation game.
The big non-optimal part, is every single directory's version of the image is treated as brand new. If anyone can solve this one for me, that'd be nice. If I figure out what to do to fix it myself, I will post back with my solution.
SOLVED
This solution won't interest anyone familiar with web programming. Its more of a new user pitfall situation. When I started setting up NancyFX I read the documentation fairly thoroughly (even if I didn't get it all on the first read). When I got to the web.config part, I first checked the Solution Explorer in VS and I didn't see one. So I just went into my project directory and created one (And there-in lies the problem). The one I made never applied settings to the project.
I figured it was a concept error, I just didn't know enough, to know where to look.\
Thx for the community's help! Hopefully my experience helps some other 1st time user out.

Why is my MPMediaItem NowPlayingItem returning null?

I am incorporating the iPod player in my app. I am able to create a queue, then play the songs. I am not able to get the current song's property values. I have registered for the notifications and the log shows the notifications are bing triggered.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
NSLog(#"currentItem = %#", currentItem);
Log output shows: currentItem = (null)
I'm running Xcode 4.5.2 iOS 6.0.
Any help is greatly appreciated.
For anyone else who may run into the same issue, the problem was that I synced my Music after running my application. You need to observe for Library changes:
MPMediaLibraryDidChangeNotification
[[MPMediaLibrary defaultLibrary] beginGeneratingLibraryChangeNotifications];
You wrote NSLog(#"currentItem = %#", currentItem); in your codes but maybe you have not got a full understand of what MPMediaItem is.
MPMediaItem is not NSString, and that's why you got null here. MPMediaItem has a lot of properties including song title, album name and artist name. To access the properties of MPMediaItem such as the title, use valueForProperty: method.
NSLog(#"currentItem = %#", [currentItem valueForProperty:MPMediaItemPropertyTitle])
Something like this.
I also had the problem that I mixed by accident the application player
[MPMusicPlayerController applicationMusicPlayer]
and the ipod player
[MPMusicPlayerController iPodMusicPlayer]
I was using the iPodMusicPlayer for playing music and tried to adjust the volume of the applicationMusicPlayer by accident.
So just beware not to mix them unintentionally ;-)

Resources