Callback of trash button not called - ios

I am developing my first application with Titanium Alloy. For iOS i use the native iOS trash button, using systemButton="TRASH". For that button i also have an onClick handler, onClick="deleteReckon". However, the deleteReckon method is not called upon clicking the trash button.
This is the "reckonDetails.xml" view for iOS (hence, included in an "ios" directory in the "views" directory) :
<Alloy>
<Window class="container">
<!-- Make a toolbar for delete and info buttons -->
<Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false">
<!-- The Items tag sets the Toolbar.items property. -->
<Items>
<Button id="info" systemButton="INFO_LIGHT" />
<FlexSpace/>
<Button id="del" onClick="deleteReckon" systemButton="TRASH" />
</Items>
</Toolbar>
<!-- We will display all reckon detail, date, total, ... -->
<View layout='vertical'>
<Label id="dateLabel"></Label>
<!-- ... OTHER LABELS ... -->
</View>
</Window>
</Alloy>
And this is the "reckonDetails.js" controller :
var args = arguments[0] || {};
// Fill in all labels of this view
$.dateLabel.text = "Date: " + args.date || 'Unknown Date';
// ...
function deleteReckon() {
console.log("deleteReckon called"); // Is never displayed
// Delete the selected reckon (this element of the collection)
var selectedReckon = args.selected_reckon;
selectedReckon.destroy();
// Go back to the index page
var args = {};
var indexView = Alloy.createController("index", args).getView();
indexView.open();
}
I put a console.log(...); statement in it to check if the function is called, but it is not..
And finally this is my "reckonDetails.tss" style (not sure if this is relevant for the problem?) :
".container[platform=ios]" : {
backgroundColor: 'white'
},
"Label": {
font: {
fontSize: '20'
},
left: '10'
},
"#dateLabel": {
font: {
fontSize: '30'
},
left: '10'
}

I've tested iOS system TRASH button on Titanium Alloy and Classic project and it's working just fine for me. Please have a look on my code below,
var win = Ti.UI.createWindow({
title : 'Window',
backgroundColor: '#white'
});
var trash = Titanium.UI.createButton({
systemButton: Titanium.UI.iPhone.SystemButton.TRASH,
});
flexSpace = Titanium.UI.createButton({
systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});
var toolbar = Titanium.UI.iOS.createToolbar({
items:[trash, flexSpace],
bottom:0,
borderTop:true,
borderBottom:false
});
win.add(toolbar);
trash.addEventListener('click', function(){
console.log("Treash called");
});
win.open();
Hope you can now find what you are looking for. For more details, please check the documentation from here at http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.SystemButton-property-TRASH and http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.Toolbar.
Thanks

Related

Status bar style in NativeScript

I'm trying to reproduce the effect seen on first page here: https://github.com/sebawita/starships, where there is a status bar with light content and no action bar.
I have been trying the instructions specified here: https://github.com/NativeScript/nativescript-angular/issues/1779#issuecomment-522586849
I'm working with NativeScript Vue rather than angular, but I don't suppose it matters. Here is my component code:
<template>
<Page
class="page"
ref="page"
statusBarStyle="light"
#loaded="onPageLoaded()">
<GridLayout rows="*, 60, 60, 20, 60, *">
<Label row="0" textWrap="true" class="header" text="Starship Service" />
<TextField
id="emailField"
hint="Email"
keyboardType="email"
returnKeyType="next"
autocorrect="false"
row="1"
class="textfield"
ios.clearButtonMode="1"
ref="field1" />
<TextField
row="2"
secure="true"
hint="Password"
returnKeyType="send"
class="textfield" />
<Button row="4" text="Log in" />
</GridLayout>
</Page>
</template>
<script>
import { topmost } from "tns-core-modules/ui/frame";
import { isIOS } from "tns-core-modules/platform";
export default {
methods: {
onPageLoaded: function(args) {
console.log('page loaded');
if (isIOS) {
Object.defineProperty(UIViewController.prototype, 'preferredStatusBarStyle', {
get: function () {
return this._preferredStatusBarStyle || UIStatusBarStyle.Default;
},
enumerable: true,
configurable: true
});
let controller = topmost().ios.controller;
controller._preferredStatusBarStyle = UIStatusBarStyle.Default;
controller.setNeedsStatusBarAppearanceUpdate();
}
console.log("page loaded done");
},
},
computed: {
message() {
return "Welcome to the first version of the starship app :-)";
}
}
};
</script>
<style scoped lang="scss">
.page {
background-image: url("https://raw.githubusercontent.com/sebawita/starships/master/icons/space-bg.jpg?raw=true");
color: #fff;
}
</style>
I have this in my Info.plist file:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
You may natively set the status bar style on your page loaded events
HTML
<Page class="page" #loaded="onPageLoaded">
JS
onPageLoaded: function(args) {
let controller = args.object.frame.ios.controller;
controller.navigationBar.barStyle = 0; // `0` for Black or `1` for Light
}
You can also hide the action bar for each component.
import { Page } from 'tns-core-modules/ui/page/page';
constructor(
private page: Page) {
page.actionBarHidden = true;
}
Like was answered in another comment, you need to make sure your Info.plist file has this entry:
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
The crucial bit of code needed was added in either NativeScript 6.4 or 6.5 here:
https://github.com/NativeScript/NativeScript/pull/8241/files
This the iOS preferredStatusBarStyle() function on the NativeScript Page object. NativeScript-Vue exposes this as a prop that you can pass in 'light' or 'dark' values to. See the updated Vue documentation.

Mode in react native picker not working

I want to make a gender selection using picker. but the mode is not working in ios. Im not sure in android.
<Picker
style={{justifyContent: 'center',backgroundColor: 'white'}}
selectedValue={this.state.gender}
onValueChange={(gender) => this.setState({ gender })}
mode='dialog'
>
<Item label="Male" value="Male" />
<Item label="Female" value="Female" />
</Picker>
Hope anyone could give some suggestion..
Thank you
The <Picker> component renders as a UIPickerView on iOS - that's what you're seeing there. This picker is rendered in-place rather than in a modal (as is the case on Android) - the mode prop you specified only applies to Android.
There are two options: render the picker within something like a <Modal> or use a different component entirely.
I solved this type of issue by doing like this.
import PickerExample from './PickerExample.js';
class Sample extends React.Component {
constructor(props) {
super(props);
this.state = {gender: '',};
this.updateGender = this.updateGender.bind(this);
}
updateGender(val){
this.setState({
gender: val
},function(){
alert("callback function as your wish")
});
}
render(){
return (
<PickerExample gender={this.state.gender} updateGender={this.updateGender.bind(this)} />
);
}
The PickerExample.js file look like this.
export default PickerExample = (props) => {
return (
<Picker selectedValue = {props.gender} onValueChange = {props.updateGender}>
<Picker.Item label = "MALE" value ="Male" />
<Picker.Item label = "Female" value = "female" />
</Picker>
);
}
I use the .ios.jsx extension for the iOS specific picker. Which I code as follows:
export const SelectWidget = ({
selectedOption,
setSelectedOption,
placeholderLabel,
options
}) => {
const items = options.map((option) => {
return <Picker.Item
key={option.key ?? option.label}
label={option.label}
value={option.value}
/>;
});
return (
<Picker
onValueChange={(value) => {
setSelectedOption(value);
}}
placeholder={{
label: placeholderLabel,
value: null,
}}
selectedValue={selectedOption}
style={{
width: '100%', // fill up the width of the device (without this, nothing gets displayed
}}
itemStyle={{
height: 150, // this reduces the height of the selector
color: colors.text, // if you're in dark mode set this to white.
}}
>
// default item
<Picker.Item label={placeholderLabel} value={null} />
{items}
</Picker>
);
};

Tap action on stack view not working properly when text field selected for iOS with Nativescript

So I'm using Nativescript to create app for both Android and iOS and I'm having some problems with iOS.
So I have a stack view where I have added a tap action, called "closeKeyboard" (currently just log message to console).
Inside the stack view I have text field.
The problem is that when I press on the text field, the stack view action also gets triggered.
On Android it works as expected - selecting text field doesn't trigger stack view action.
Here is the code for main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<StackLayout tap="closeKeyboard">
<Label class="conf-button-label" text="Netto sum" />
<TextField text="{{ sum }}" hint="Type number" returnKeyType="done" keyboardType="number" keyboardPatter="[0-9]*" returnPress="done" id="sum" col="0" row="0" class=""/>
</StackLayout>
</Page>
Here is a code for main-page.js
var createViewModel = require("./main-view-model").createViewModel;
function onNavigatingTo(args) {
page = args.object;
}
function done(){
console.log('Input Done');
}
function closeKeyboard(page){
console.log('Close Keyboard Tapped');
}
exports.done = done;
exports.closeKeyboard = closeKeyboard;
exports.onNavigatingTo = onNavigatingTo;
Can anyone help me with this?
In case you want to create something like javascript blur event or just to hide keyboard, when you tap outside the TextView, you could set custom gesture for ios using native code. You could review the bellow attached example:
main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="loaded">
<StackLayout id="stack">
<Label text="Tap the button" class="title"/>
<Button text="TAP" tap="{{ onTap }}" />
<Label text="{{ message }}" class="message" textWrap="true"/>
<TextView id="text" text="" hint="Enter some text" backgroundColor="yellow" updateTextTrigger="focusLost"/>
</StackLayout>
</Page>
main-page.js
var createViewModel = require("./main-view-model").createViewModel;
var gestures = require("ui/gestures");
var observableModule = require("data/observable");
var observableObject = new observableModule.Observable();
var TapHandlerImpl1 = (function (_super) {
__extends(TapHandlerImpl1, _super);
function TapHandlerImpl1() {
_super.apply(this, arguments);
}
TapHandlerImpl1.initWithOwner = function (owner) {
var handler = TapHandlerImpl1.new();
handler._owner = owner;
return handler;
};
TapHandlerImpl1.prototype.tap = function () {
this._owner.ios.resignFirstResponder();
};
TapHandlerImpl1.ObjCExposedMethods = {
"tap": { returns: interop.types.void, params: [interop.types.id] }
};
return TapHandlerImpl1;
}(NSObject));
var tapHandler = null;
function loaded(args) {
var page = args.object;
var field = page.getViewById("text");
if (page.ios) {
tapHandler = TapHandlerImpl1.initWithOwner(field)
var recognizer = UITapGestureRecognizer.alloc().initWithTargetAction(tapHandler, "tap");
page.ios.view.addGestureRecognizer(recognizer);
}
field.addEventListener(observableModule.Observable.propertyChangeEvent, function(pcd){
console.log(pcd.eventName.toString() + " " + pcd.propertyName.toString() + " " + pcd.value.toString());
});
page.bindingContext = observableObject; }
exports.loaded = loaded;
However the same problem have been discussed also in this GitHub issue.
I think the only way is to move the closeKeyboard() from Stacklayout to the child view Label. Or you can try to define a separate tap action for the textfield to override the tap action of stacklayout.

Unable restrict the click event listener outside region of LeftNavButton and RightNavButton?

I am created one sample alloy app in appcelerator studio.
When I click on outside button(image) also event is performed.
How to restrict the click event, If I perform event outside the LeftNavButton or RightNavButton.
Can one help me out.
signIn.js:
$.signInWin.addEventListener('open', function() {
Ti.API.info('signInWin open');
var titleLabel = Ti.UI.createLabel({ text: 'Log In', width: Ti.UI.SIZE});
$.signInWin.setTitleControl(titleLabel);
var leftButton = Titanium.UI.createButton({
backgroundImage : '/left_arrow.png'
});
$.signInWin.setLeftNavButton(leftButton);
var rightButton = Titanium.UI.createButton({
backgroundImage : '/right_arrow.png'
});
$.signInWin.setRightNavButton(rightButton);
leftButton.addEventListener('click', function(e) {
Ti.API.info(' event performed on left button');
});
rightButton.addEventListener('click', function(e) {
Ti.API.info(' event performed on right button');
});
});
signIn.tss:
"#signInWin":{
backgroundColor: '#ffffff',
}
"#signInNav":{
backgroundColor: '#00a2f7',
}
signIn.xml:
<Alloy>
<NavigationWindow id="signInNav" platform="ios">
<Window id="signInWin">
</Window>
</NavigationWindow>
</Alloy>
Sample Screen View
The clickable area of a rightNavButton/leftNavButton extends the button itself by a few pixels. That is a native behavior of iOS. To resolve this, you could wrap the button inside a Ti.UI.View which has a fixed height. That should resolve your problem pretty easy!

need some guidance in dialog box implementation

I have a cakephp view (index.ctp) where I have edit button. On button edit I want the jquery dialog box open with what i have in edit.ctp. (Currently if I go to edit.ctp, it works fine but I am trying to use model / dialog box so the user stays on same page)
This is what I have in my index.ctp
<td>
<?php echo $this->Html->link($team['Company']['name'], array('action' => 'edit_reload','team_id'=>$team['Team']['id']), array('id'=>"dialog_link", 'class'=>"ui-state-default ui-corner-all"));?>
</td>
<div id="dialog" title="Dialog Title">
</div>
Now when the link clicked I want to show the edit_reload.ctp contents here. I am totally exhausted so any help will be appreciated
thanks
In a separate JS file write the following code and add your values to the variables and include the JS file in your .ctp file.
$(document).ready(function() {
$myWindow = $('#dialog');
//instantiate the dialog
$myWindow.dialog({ height: 250,
width: 200,
modal: true,
position: 'center',
autoOpen:false,
title:'',
overlay: { opacity: 0.5, background: 'black'}
});
$J("#dialog_link").click( showDialog );
});// end (document).ready
var showDialog = function() {
var team_id = '';
var url = '/controller/action/' + team_id;//Apply path to controller, action
$.post(url, function(res) {
$myWindow.dialog({
title:'Give Title'
});
$('#dialog').html(res);
$myWindow.show();
});
}
In .ctp file use the link as follows-
echo $this->Html->link($team['Company']['name'],'#', array('id'=>"dialog_link", 'class'=>"ui-state-default ui-corner-all"));
I have show you an example.You can also write the js code in the .ctp file also.

Resources