nativescript-checkbox icon indicating copy to clipboard operation
nativescript-checkbox copied to clipboard

Tap not working

Open Mflm opened this issue 6 years ago • 14 comments

Hi

I have the latest version of this plugin, also the NS 3.0+.

Now I can't call the tap method, only if I click the text.

The solution that I implemented is set the checkbox children of a Stack layout, and the parent with the tap event.

Mflm avatar Aug 30 '17 18:08 Mflm

Have you tried the checkedChange event instead?

EddyVerbruggen avatar Aug 30 '17 18:08 EddyVerbruggen

How do I make it work? example: XML <CheckBox:CheckBox checkedChange="checkTap"/>

exports.checkTap = function(args) { console.log("TAP"); }

Mflm avatar Aug 30 '17 18:08 Mflm

Hi again

The issue is present only in iOS. Also in iOS the alignment of checkbox is wrong.

Mflm avatar Aug 31 '17 15:08 Mflm

I agree with author: tap event doesn't work on iOS if i click on checkbox. Can you help with this trouble?

mrkorsar avatar Oct 23 '17 11:10 mrkorsar

Hi

An alternative solution is the CheckBox within the StackLayout:

<StackLayout width="50px" height="50px" tap="getCheckProp"> <CheckBox:CheckBox tap="getCheckProp" checkedChange="checkTap" checked="{{checkProp}}" id="myCheckbox" row="0" rowSpan="2" col="0" fillColor="red" loaded="thingSwitchLoaded"/> </StackLayout>

Mflm avatar Oct 23 '17 12:10 Mflm

No, checkbox intercepts the tap event

mrkorsar avatar Oct 23 '17 13:10 mrkorsar

The tap event not works, only if I check the event in one function:

var checkID = customControl.parent.parent.getViewById("myCheckbox"); var checkStatus = checkID.checked; if(checkStatus.toString() == "true") { }

But if it is within a list, the tap in a Layout.

Mflm avatar Oct 23 '17 13:10 Mflm

Any update here ? I tried the workaround with StackLayout but it doesn't work.

alexandruantonica avatar Nov 01 '17 17:11 alexandruantonica

In my case this helped me:

HTML

<CheckBox #elem [checked]="item.isChecked" class="checkbox" checkStyle="checkbox_yellow" (checkedChange)="elem.checked !== item.isChecked && toggleChecked(item)"></CheckBox>

TS public toggleChecked(item: LsItem) { item.isChecked = !item.isChecked; }

I mean about this line elem.checked !== item.isChecked. I don't know but maybe it could help you @alexandruantonica in your case

mrkorsar avatar Nov 02 '17 05:11 mrkorsar

Thanks @mrkorsar The checkbox works but the main issue here is the event is not triggered. Event checkedChange doesn't work on iOS and as you can see in this file, the event is not supported. The event works properly on Android.

alexandruantonica avatar Nov 02 '17 11:11 alexandruantonica

Any Solution for this ?

OPADA-Eng avatar Mar 19 '18 07:03 OPADA-Eng

I have a workaround for angular apps, using ngModel and defining a setter. on .html: <CheckBox [(ngModel)]="selected"></CheckBox> and on .ts: set selected(value: boolean) { this._selected = value; console.log('tap'); }

yassernasc avatar May 21 '18 13:05 yassernasc

Can still reproduce this issue. any workarounds for NS core or NS + typescript?

aaayushsingh avatar Oct 07 '19 10:10 aaayushsingh

Checkbox extends Button and overrides it's initNativeView call. The core framework initiates tap handler in that method. Below override in your project should fix the issue.

import { CheckBox } from "nativescript-checkbox";
import { Button } from "tns-core-modules/ui/button";

(<any>CheckBox.prototype).originalinitNativeView = CheckBox.prototype.initNativeView;
CheckBox.prototype.initNativeView = function() {
    Button.prototype.initNativeView.call(this);
    (<any>CheckBox.prototype).originalinitNativeView.call(this);
};

manojdcoder avatar Nov 29 '19 05:11 manojdcoder