According to most Famo.us tutorials, you only need to add the following line to make Fastclick work (Famo.us university Timbre project)
var FastClick = require('famous/inputs/FastClick');
However, I have found that that alone doesn't kill the 300ms delay in an iPhone 5. Is there any additional configuration to be done? I included the FastClick line for the following code:
this.accordionSurface.on('click', function() {
this._eventOutput.emit('editItem', this.model);
}.bind(this));
This is part of a AccordionView that is then added to a Scrollview through a ViewSequence (copied from the Taasky demo at https://launch-demos.famo.us/Taasky/). However, unlike the demo, tapping on my items takes some time to react. The animation done after tapping on my item looks like this:
AccordionView.prototype.hide = function(scrollView) {
this.accordionModifier.setOpacity(
0,{ duration : 100, curve: 'easeInOut' },function(){
this.size.set(0.001, {duration: 300, curve: 'easeOut'}, function(){
}.bind(this));
}.bind(this));
}
The animation works fine and smooth, but it's triggered with a bit of delay that I assume comes from the lack of the FastClick integration. I had moved the require line around the AppView, main.js without result and I have yet to find an example that does anything else that calling FastClick with the require line.
Any hints?
It's not exactly a fix but we've noticed that the 'touchend' event (or 'end' event in a GenericSync) fires reliably and could be used as an alternative to click with a bit of tinkering.
Related
I am using a Column chart from the Google Visualization API, and have set up a "click" event for when I click on one of my columns as so:
google.visualization.events.addListener(chart, 'select', function(event) {
if (!isWebview) {
log.logInfo("Selected Sum");
$("#reportBody").trigger("app:update", { toXYZ: true});
} else {
}
});
However, this fires 4 times every time that I select a bar in the chart. This also happens to be the amount of rows that I have in the chart - could this be connected?
Thanks in advance.
Answer:
I found the problem - there were two. Firstly, the html file for this js file loaded the same js code twice - once for ios and once for android, but on the browser loads both, thus adding the same event listeners twice.
Furthermore, both these ways of setting the onLoad callback were used:
google.charts.load('visualization', '1', {
'packages': ['corechart', 'table'],
'callback': drawAll
});
and
google.setOnLoadCallback(drawAll);
The latter of which is a deprecated version if I'm not mistaken.
Therefore, the drawAll function, which creates the event listener, ended up being called 4 times, so I had 4 event listeners for the same event, all executing the same code.
I am trying to simply execute code on a click of a bluetooth headset button in a SwiftUI 2.0 app, but after trying many different codes, nothing have worked... Does someone have solved this issue?
Based on apple docs and some answer I found on StackOverflow (https://stackoverflow.com/a/58249502/13207818), I tried this simple code
import SwiftUI
import MediaPlayer
struct ContentView: View {
init() {
MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true
MPRemoteCommandCenter.shared().pauseCommand.addTarget(handler: { (event) in
print("Pause")
return MPRemoteCommandHandlerStatus.success
})
MPRemoteCommandCenter.shared().playCommand.isEnabled = true
MPRemoteCommandCenter.shared().playCommand.addTarget(handler: { (event) in
print("Play")
return MPRemoteCommandHandlerStatus.success
})
MPRemoteCommandCenter.shared().togglePlayPauseCommand.addTarget (handler: { (event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus in
// middle button (toggle/pause) is clicked
print("event:", event.command)
return .success
})
}
var body: some View {
Text("Hello World")
}
}
Of course Enabling Background Audio as per Apple doc
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
Even tried to activate my app audio session:
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: .default, options: [.duckOthers, .allowBluetooth, .allowBluetoothA2DP])
try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
print("audioSession is Active")
} catch {
print("audioSession properties weren't set because of an error.")
print(error)
}
But everything failed...
Would someone know what I am doing wrong or would have faced such issue with swiftUI 2.0?
Thank in advance for your support
In general you shouldn’t do actions in the initializers of views. Since they represent the state of the UI, not the actual UI they could be broken down and created again whenever SwiftUI thinks it needs to.
Im not at my pc but You can probably get a Publisher for the pause button which you can bind to a view with onReceive
Finally, I got a solution for my issue.
I don't know how it works really behind but the audio focus wasn't on my app. So I've just played a silent sound for a second and I could play properly with my play/pause button. I know that it's not a proper solution, but it works!
This reminds me of a similar bug on the galaxy s8...
If I find a better one, I'll keep you posted.
So I'm making a button for a "New Note" in Swift UI similar to the Apple Notes app.
Right now my "New Button" is a "Navigation Link" like so:
NavigationLink(
destination: EditorView(makeNewNote())
) {
Text("New")
}
Unfortunately—this triggers my app to create a new note every time the view loaded. :(
:/
I've been looking for a way to initate a segue on button push but I'm not finding success on this yet.
When I tried a modal—I found myself having the same problem
Button("New") {
self.isNew = true
}.sheet(isPresented: $isNew, content: {
EditorView(makeNewNote())
})
I'm wondering what the best way to approach this would be.
Having no success :(
Edit:
I referred to this and the documentation but I haven’t found a way to segue via a button push which would be ideal. (The function dosent get triggered in the closure :)
https://www.hackingwithswift.com/quick-start/swiftui/how-to-push-a-new-view-onto-a-
Also...if you were curious what makeNewButton() does—it basically inserts a new Core Data object into my app’s managed context.
I'm not entirely sure, but it kinda sounds like to me your problem lies in your model. Because each time your View loads it calls the makeNewButton() function right?
Maybe you can fix the problem by displaying the "new note" view and having an extra "Save" button that only makes changes to your model once it's triggered.
Alternatively, you could use context.rollback() to discard changes. Also, check out this Project. It's Beta 4 but works just the same and imo is a good example how to use CoreData with SwiftUI. :)
What is the best technique to generically change to a busy cursor during transition to a new route in Ember.js (1.13.10)? With data retrieval, this may take a couple of seconds.
The answer here indicates a method to do this with saving data:
Changing mouse cursor while Ember content is saving
...and indicates this is very straight forward with route transitions, but I can't seem to find an example or anything in the documentation.
Thanks in advance for any help on this.
We can use loading hook of Route.
app/routes/application.js:
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
loading(transition, route) {
$('body').css({ cursor : 'wait' });
this.router.one('didTransition', () => {
$('body').css({ cursor: 'default' });
});
return true; // Bubble the loading event
}
}
});
Working demo. (output is sandboxed so make sure your mouse is over body in output window)
Full code behind demo.
I've used $('body') as element to style cursor. You can probably use more global approach.
How to remove animation from object in raphael?
var animation = Raphael.animation({opacity:.2}, 1000);
var circle = paper.circle(0, 0, 5).animate(animation.repeat(Infinity));
I want to perform animation on object until some moment in time. And the question is how to remove/stop animation in that specific moment?
Well, I really don't know why, but the fiddle works if don't pass any arguments to the stop method. Despite what Raphael's documentation says, I found a working example of an animation stopping in this site (is not the most beatiful site, by the way, but they have an example for each raphael method!)
Here you have the Fiddle working. http://jsfiddle.net/fKxqS/2/
Enjoy!
If you want to stop the animation after a specific timelapse...
setTimeout(circle.stop(animation), 500) //500 is milliseconds, so it's 0.5s
If you want to stop the animation after an event, such as a click
circle.click(function(){
circle.stop(animation)
})
Edit: Seems Raphael doesn't stop if repeat is set to Infinite, perhaps somebody knows a workaround, here's the fiddle: http://jsfiddle.net/fKxqS/