refundRequestSheet done button is not working properly [SwiftUI 4, iOS16.1+] - ios

I am having an issue with refundRequestSheet. So basically, my issue is that everything is presented just fine, I can get through the refund process, but at the end of the process where we are having done button, after I press the done button nothing is happening, result is not being called - it looks like the button is not actually calling any action.
The only way for me to close the screen is to actually swipe the sheet down, and then the result of onDismiss sometimes is failure and sometimes is a success.
I also investigated other type of sheets such manageSubscriptionsSheet, and this is having the same issue basically.
I also tried both simulator and the actual device, still nothing.
.refundRequestSheet(for: viewModel.transactionID ?? 0, isPresented: $viewModel.showRefundSheet, onDismiss: { _ in
viewModel.showRefundSheet = false
})

Related

Confusing button-actions in SwiftUI

Here is some SwiftUI code in a running app I am working on:
Button(action: action) {
Image(systemName: img)
.imageScale(.large)
}
.simultaneousGesture(LongPressGesture().onEnded { _in
playLngPress = true
showingFlag = true
})
My question is about the relationship between the chunk of code executed when making a long-press on the button and the chunk of code executed when making a simple tap. I first noticed that when making a long-press, the action (for a simple tap) was also executed along side.
Though I do not think this is how it should be, I made a work-around to have things go my way.
More recently (after moving to iOS 15, though I am not 100% sure this is the Reason) I noticed that the action for the tap is not always performed when making a long-press.
Can anyone precisely explain how this is working ?

Appium Touch Actions 'Press' and 'Move To' is not working in iOS chrome app

I am learning mobile automation and I came across a scenario some thing like this
Launch chrome app in iOS
Load https://www.google.com
Hold/Press and pull down banner web element on the web page which will display some overlay with three options 'New tab, Reload & Close tab' (note: overlay will lost on releasing the banner web element)
Tap on the new tab button
So far I have written below script in python
def Test(self, driver_provider):
single_tap = appium.webdriver.common.touch_action.TouchAction(driver_provider.driver)
element = driver_provider.driver.find_element_by_accessibility_id('NTPHomeFakeOmniboxAccessibilityID')
single_tap.tap(element=element).perform()
element.send_keys('https://www.google.com')
single_tap.tap(element=driver_provider.driver.find_element_by_accessibility_id('Go')).perform()
time.sleep(1)
#Press banner and pull down will display the over scroll actions
#Then move to left to tap on the add button
banner_element = driver_provider.driver.find_element_by_accessibility_id('banner')
screen_size = driver_provider.driver.get_window_size()
height = screen_size.get('height')
width = screen_size.get('width')
single_tap.press(banner_element, x=banner_element.size.get(
'width')/2, y=banner_element.size.get('height')/2).wait(1).move_to(banner_element,
x=width/2, y=height/2).wait(0.5).move_to(banner_element, x=0, y=height/2).release().perform()
for some reason press and move_to actions are not happening and there is no error returned as well, I am not clear what went wrong here. Please share your view on what went wrong thanks.
it's failing to perform press and move to because of wait value is very small. When I use the wait(500) then the press and move to is happening.
single_tap.press(banner_element, x=banner_element.size.get(
'width')/2, y=banner_element.size.get('height')/2).wait(500).move_to(banner_element,
x=width/2, y=height/2).wait(500).move_to(banner_element, x=0, y=height/2).wait(500).release().perform()

Layout changes do not apply in tests

I have a button that allows to hide itself and another widget when pressed. When it is hidden, a new button appears on the screen which can undo (show) the previous button and widget again.
I'm pretty sure my implementation for this works because I've tested it on multiple devices without any problems, but whenever I try to write a formal test for it, something goes wrong. I'm using the following code to test my widget:
await tester.tap(find.widgetWithText(GestureDetector, "HIDE"));
expect(testContainerState.ifContainerWithOptionsIsDisplayed, false);
print(find.byType(GestureDetector));
await tester.tap(find.widgetWithText(GestureDetector, "SHOW"));
expect(testContainerState.ifContainerWithOptionsIsDisplayed, true);
The first two lines are there to tap the button and check whether ifContainerWithOptionsIsDisplayed changed. In my implementation, this is done in a setState method and should repaint to hide the widget and button and show the new button.
In the third line, I check how many GestureDetectors I can still find after what should be a repaint. The output of that print statement still shows me that all of the GestureDetectors of the widget that should now be hidden are still being found.
In the 4th line, I try to find my SHOW button that should now be visible because of the repaint. But no element is found.
Again, I'm pretty sure the code for my widgets are correct because I've tested this test case manually without any issues. Perhaps I'm missing some knowledge about Flutter tests. Could someone please fill me in?
await tester.pump();
or just
tester.pump();
should do that
See also
https://docs.flutter.io/flutter/flutter_test/WidgetTester/pump.html
https://docs.flutter.io/flutter/flutter_test/WidgetTester/pumpAndSettle.html
https://flutter.institute/flutter-and-widget-tests/

Restarting UIActivityIndicator on keystroke

If I remember correctly before I upgraded to Swift 3, the following code worked to achieve the look of the spinner starting at 0 progress again for each stroke. I'm looking for the exact same effect Instagram uses in their searching.
spinner.stopAnimating()
spinner.startAnimating()
It used to just completely refresh the spinner. Now, it's just pausing the spinner for a millisecond while you're typing then continuing on. Looks very jittery.
I've got "hides when stopped" checked, and I've tried adding some spinner.hidden = true/false in there respectively to stopping/starting, that also did not work.
Any idea what got changed/ what I need to do to regain the effect?
Changing it's view style causes it to reset it's animation:
spinner.stopAnimating()
spinner.activityIndicatorViewStyle=UIActivityIndicatorViewStyle.white
spinner.activityIndicatorViewStyle=UIActivityIndicatorViewStyle.gray
spinner.startAnimating()

UIButton text not updating

A "tried and true" pattern I've used in my iOS Swift app is that I have several areas with UIButtons. When the button is pressed, it fires off some net code that connects to my API. While this is happening, I have the button text say "please wait, loading" and I disable the button. When the queued action finishes in my callback I have the button text enable and change back to the original state. It works great.
I recently added something not using NSURL/NSDATA (it's just a file writer). I copied all the same GCD queue code and oddly enough it doesn't update the button text.
Here is my code. When you tap the button, the text becomes invisible until the callback finishes, and then it just restores back. Oddly enough if I change my simulator to iPad Pro it actually works (??) and says "please wait, downloading". If I switch to iPhone 6s it doesn't work.
#IBAction func btnGenerateCSV(sender: UIButton) {
//Grab the original text of the button to restore later after done
let originalButtonText = sender.titleForState(UIControlState.Normal)
//Localized is an extension function I wrote.
//As you can see I got crazy here adding all the UI States as a last ditch attempt to see if that was the reason.
sender.setTitle(Localized("Downloading"), forState: UIControlState.Normal)
sender.setTitle(Localized("Downloading"), forState: UIControlState.Disabled)
sender.setTitle(Localized("Downloading"), forState: UIControlState.Highlighted)
//I've tried moving this before the setTitle. No avail.
sender.enabled = false
//I've tried the other queues as well, and even just tried dispatch_async(dispatch_get_main_queue()) but no luck
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) { [unowned self] in
CsvReportWriter.GenerateReport()
{
r in
dispatch_async(dispatch_get_main_queue()) {
FileManager.WriteToFile(r, filename: self.filename)
if FileManager.FileExists(self.filename) {
self.docController = UIDocumentInteractionController(URL: FileManager.GetURLOfFile(self.filename))
self.docController.presentOptionsMenuFromRect(sender.frame, inView:self.view, animated:true)
}
//Restore button state and text b/c we're done
sender.enabled = true
sender.setTitle(originalButtonText, forState: UIControlState.Normal)
}
}
}
}
Any ideas? If I swap out the CsvReportWriter.GenerateReport() code with some other async code that does a call out to my API, it works.
Thanks so much!
So I wanted to post an answer that I thought was interesting - I had a different account logged in to my iPad Pro simulator.. and noticed that the label correctly appeared. In iPhone 6 it did not. I was logged into a different account.
So what was the difference? There were about 1,000,000 test rows to generate in the iPad pro, and 3 in the iPhone, so everything finished so fast there was no UI to even update.
I introduced a delay just as a test, and noticed that in fact it works / exports so that's actually what it was.
So it turns out things were running so fast there wasn't even time to update to 'please wait' lol
Sorry to bother anyone but feel free to use the above code as it should be effective to do what you need :)

Resources