BottomSheetDialogFragment- Close only on full swipe Kotlin Android - android-dialogfragment

I have a BottomSheetDialogFragment to show list of items inside a fragment. Each list item got a click event mapped. The problem here is, most of the times click action turns into swipe down action and BottomSheetDialogFragment is getting closed. I have no custom events to monitor the events in my code.
dialog?.also {
it.findViewById<View>(R.id.design_bottom_sheet)?.let { bottomSheet ->
bottomSheet.layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT
BottomSheetBehavior.from(bottomSheet).state = BottomSheetBehavior.STATE_EXPANDED
BottomSheetBehavior.from(bottomSheet).skipCollapsed = true
}
}
I have to prevent the close event of BottomSheetDialogFragment on click action which turns into swipe down action because of small extra movement added. This could happen and needs to handle since this application will be used by general public.
Can anyone suggest to find the swipe distance on BottomSheetDialogFragment. So that if the value is lower, the dialog will remain open. And if the value if high because of intentional swipe event, the dialog will get dismissed.

Related

Button can only be clicked once (Unity)

I'm fairly new to this.
When I click on the button to rebind the jump key, the rebind works fine. First the panel "Waiting on rebinding..." pops up, then I press the key, I want jump to be, then the new key shows up on the button as the binding.
This works only once though. When I want to click on the same button again, it doesn't allow me to click on it. The button doesn't even change color anymore, when you hover over it.
What I tried to solve this was to duplicate the button. When I click on either of the buttons and rebind the jump key, it works the first time, but not after that. Both buttons are unclickable. Closing and opening the button panel doesn't work either.
Here is the code for the OnClick() on the button:
public void JumpStartRebinding()
{
startRebindObject.SetActive(false);
waitingForInputObject.SetActive(true);
movement.PlayerInput.SwitchCurrentActionMap("UI");
jumpAction.action.Disable();
rebindingOperation = jumpAction.action.PerformInteractiveRebinding()
.WithControlsExcluding("Mouse")
//.WithCancelingThrough("<Keyboard>/escape")
.OnMatchWaitForAnother(0.1f)
.OnComplete(operation => JumpRebindComplete())
.Start();
}
private void JumpRebindComplete()
{
int bindingIndex = jumpAction.action.GetBindingIndexForControl(jumpAction.action.controls[0]);
bindingDisplayNameText.text = InputControlPath.ToHumanReadableString(
jumpAction.action.bindings[bindingIndex].effectivePath,
InputControlPath.HumanReadableStringOptions.OmitDevice);
jumpAction.action.Enable();
rebindingOperation.Dispose();
startRebindObject.SetActive(true);
waitingForInputObject.SetActive(false);
movement.PlayerInput.SwitchCurrentActionMap("Player");
}
The issue doesn't appear to be with your code. I was having this exact same issue a few days ago. It likely has to do with the fact that a UI object is "covering up" the button. A first step I'd take is making sure that nothing is obscuring your button after re-enabling it (often times, TextMeshProUGUI objects with "Raycast Target" enabled are the culprit).

Detecting MouseUp or dragging session "willEnd" on NSDraggingSession in Cocoa OSX

I've got an app where I'm allowing items to be dragged between NSTableViews. When the drag leaves the table, the table closes around the starting location of the removed cell.
When a user lets go of an item and the drag will be cancelled, I'd like to animate TableCellView's starting location opening back up at the same time as the dragItem is being returned to the list, so that it looks like the tableView is "opening back up" to receive the cancelled item.
I'm having trouble detecting the moment that the user releases the mouse and the event is cancelled. Both "draggingEnded" and "draggingSession( endedAt )" fire after the animation has completed. Does anyone have any idea how to capture the "mouseUp" moment of the cancellation?

GWT Forward Button

I'm having an issue handling the forward button.
Basically, when a user is on a page and has made changes without saving then presses the backwards or forwards button they are presented with a prompt and two options: Leave or Stay.
I have implemented the backwards button fine, and choosing to stay on the page works well using History.newItem(currentToken) - the back button is still clickable.
However with the forwards button, if I use History.newItem(currentToken), it brings this to the front of the history stack and the forward button can no longer be clicked.
History.replaceItem(currentToken) causes the same issue.
How do I handle the cancelling of a forwards action so that I stay on my current page, but the forwards button is still enabled?
#Override
public void onValueChange(ValueChangeEvent<String> event) {
logger.info("back button pressed: " + event.getValue());
String evenVal = event.getValue();
String token = History.getToken();
AbstractPresenter presenter = sessionKiosk.getCurrentlyShowingPresenter();
if (presenter instanceof NSRCommonWorksheetPresenter && sessionKiosk.isDirty()) {
((NSRCommonWorksheetPresenter)presenter).setHistoryToken(event.getValue());
((NSRCommonWorksheetPresenter)presenter).showUnsavedChangesLeavingPageDialog();
}
else {
handleHistoryEvent(event.getValue());
}
}
The dialog is shown and when I click on stay on page the following is called.
public void stayOnCurrentPage() {
if (eventMap.get(prevPage) != null) {
History.newItem(prevPage, false);
}
}
Update: Basically history.newItem(value) removes the use of the forward button. Is there another way to cancel the event? If I just do nothing, th page stays where i want but the url still updates
None of the 3 options in the else statement seem to work.
Thanks.
You can simply cancel the event without touching History or tokens.
UPDATE:
It appears from your code that you are not intercepting the event (back/forward button), but let it go through, get the new token, and then force a return to the previous state under certain circumstances.
I suggest using Activities and Places pattern where every "place" within your app has a corresponding "activity". Each activity in your app will implement GWT Activity interface which includes mayStop() method. This method is called before a user navigates away from a specific place in your app, giving you an opportunity to warn a user and cancel the navigation if necessary.
In general, this pattern offers a very robust support for the History mechanism, covering many use cases.
If you want to support History mechanism yourself, take a look at PlaceChangeRequestEvent - it allows you to warn a user who tries to navigate away from a place in your app.

dojox/gesture/swipe prevents the html select to open dropdown

can anyone please explain to me why the html SELECT control (or any other control like BUTTON) placed inside the div (that is registered with dojox/gesture/swipe events) cannot be opened? I'd welcome any workarounds pls
require({
}, [ 'dojo/dom', 'dojox/gesture/swipe', 'dojo/on', 'dojo/_base/event' ], function(dom, swipe, on, event) {
var div = dom.byId('testSwipe');
var isSwipe = false;
on(div, swipe.end, function(e) {
console.log("### SWIPE");
});
});
http://jsfiddle.net/zLyck884/
based on the documentation here, particularly the image : http://dojotoolkit.org/reference-guide/1.10/dojox/gesture.html
the image depicts how the dojo standardizes the events (also for desktops) and how the swipe is just another layer of the touch events. so I reckoned if the mouse events are replaced by touchstart or something, then it most likely blocks the default mouse action...
once I've stopped propagating the event (on the SELECT) further, then it worked ok.
query("select", this.domNode).on(touch.press, function(e){e.stopPropagation()});
where this.domNode is the element on which the swipe is enabled
on(this.domNode, swipe, lang.hitch(this, "_onSwipe"));
Unfortunately the swipe (touch) event overriding the default behaviour is not very handy, I just left dojox/gesture/swipe or touch for now. Seems like I'll rather implement my own touch event handling.

Google Closure add onclick to button after adding this button with custom editor plugin

I am making a custom plugin for the editor provided by Google Closure. The plugin makes it able to add a button.
I am having problems by setting an onclick on the button, the other values are nicely set.
button.innerHTML = event.label;
button.className = event.initialClass;
var extraClasses = event.extraClasses;
if (extraClasses)
{
button.className += ' ' + extraClasses
}
button.onclick = function() { event.onclick };
Does anyone know what I am doing wrong and how I can fix this?
After creating a button it is added to the editors SeamlessField. A second problem that I currently have is that after creating the button, my pointer is inside the button and I can't seem to get it out of there.
I've got the follow piece of code for handling this at the moment. The var button is the created button. button contains: <button class="orange">test</button>
// We want to insert the button in place of the user's selection.
// So we restore it first, and then use it for insertion.
this.restoreOriginalSelection();
var range = this.fieldObject.getRange();
button = range.replaceContentsWithNode(button);
// Done making changes, notify the editor.
this.fieldObject.dispatchChange();
// Put the user's selection right after the newly inserted button.
goog.editor.range.placeCursorNextTo(button, false);
// Dispatch selection change event because we just moved the selection.
this.fieldObject.dispatchSelectionChangeEvent();
Any ideas about how I could fix this second problem aswell?
For the first, it does not look like you have begun using Google Closure event code. Wiring up the button to the 'click' event in Google Closure would be as follows:
goog.events.listen(button, goog.events.EventType.CLICK, event.onclick)
You should also be investigating the goog.dom and goog.dom.classes namespaces if you'd like to use Google Closure's wrappers around standard CSS class and text DOM manipulation.
For the second, were you testing in Chrome? If so, you might have ran into a range issue in Webkit, documented within the Closure code itself:
https://code.google.com/p/closure-library/source/browse/closure/goog/editor/range.js#174
I have gotten around this in the past by inserting an empty <span> element as a sibling after the offending element (the button, in your case), and placing the cursor next to the <span> instead. However, there's nothing stopping the user from moving the cursor back inside your button. You'll have to add more logic to prevent a user from placing the cursor within the button's text.