I've created a button that I want to have call a function on click and then again on release. A normal TouchableOpacity or other will trigger a function upon release of a click only, I need functions on both click AND release.
<View
style={styles.touchbutton}
onStartShouldSetResponder={() => this.clickOn()}
onResponderRelease={() => this.clickRelease()}>
<Text style={styles.dark}>Button</Text>
</View>
The above code works on click but not on release. I also tried onResponderReject but that doesn't work either. Hard to find what the command should be.
Had the same problem. onStartShouldSetResponder needs to return true.
onStartShouldSetResponder={(e) => {
/*do whatever*/;
return true
}}
Please Try This code For your click event it works for me :
clickOn(){
Alert.alert(
'Test Demo',
'Please Enter Valid Data',
[
//{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)
}
}
Put these two lines it works for me when you release
onStartShouldSetResponder={() => true}
onResponderRelease={() => this.onRowTap()}
Related
I am using RN 0.63 and i am facing issue in React Native core alert.It popup and disappear automatically with second.I want alert should disappear when i click on OK button.
Alert.alert(
'Alert Title',
msg, // <- this part is optional, you can pass an empty string
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{cancelable: false},
);
I ran into the same issue and was able to avoid the "automatically disappearing" Alert popup after finding a loading prop was being passed down into a child component and was being (unnecessarily, in my case) consumed.
So I resolved the issue by simply removing the prop and handling the "loading" logic in the parent component.
Please double check that there are no unintentional re-renders of your component that may cause the Alert to be dismissed.
Probably you are showing dialog right after setState. You need to show dialog once the state update is completed. If this is not doable, it's not a good idea but a workaround then simply wrap dialog within setTimeout.
setTimeout(() => {
Alert.alert(
"Title",
"Message",
[
{
text: "OK",
onPress: () => {},
},
],
{ cancelable: false }
);
}, 100);
I have a doubt and I am not able to solve the problem of having buttons to perform an action (accept or reject) within a push-notification in iOS with react-native-firebase. For Android I can do it but for iOS I can't find a way to register the action. Next I show how is the code I have.
const notificationListener = () => {
firebase.notifications().onNotification((notification) => {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setSound('default')
.setBody(notification.body)
.setData(notification.data)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setNotificationId(notification.notificationId);
if (Platform.OS === 'android') {
localNotification
.android.setBigText(notification.body)
.android.setSmallIcon('ic_noti_logo_hnc')
.android.setLargeIcon('ic_launcher')
.android.setVisibility(firebase.notifications.Android.Visibility.Public)
.android.setChannelId(CHANNEL_NOTIFICATIONS.CHANNEL_ID)
.android.setPriority(firebase.notifications.Android.Priority.High);
if (isEqual(localNotification.data.set_delay_time, "true")){
// Build an action
const acceptAction = new firebase.notifications.Android.Action('accept_action', 'default', 'Accept');
const rejectAction = new firebase.notifications.Android.Action('reject_action', 'default', 'Reject');
localNotification
.android.addAction(acceptAction)
.android.addAction(rejectAction);
}
} else if (Platform.OS === 'ios') {
localNotification
.ios.setBadge(notification.ios.badge);
}
firebase.notifications().displayNotification(localNotification)
.catch(err => console.error(err));
});
};
What I intend to do is something similar to what you find with Android but the only thing I found the most is IOSNotification.alertAction.
Could someone guide me with this? From already thank you very much!
Nico.
use "react-native-firebase" version 6. You can get the migration information from here.
You can display action buttons using Notifee and handle all the actions click event.
Define actions,
import notifee from '#notifee/react-native';
async function setCategories() {
await notifee.setNotificationCategories([
{
id: 'post',
actions: [
{
id: 'like',
title: 'Like Post',
},
{
id: 'dislike',
title: 'Dislike Post',
},
],
},
]);
}
Assign category to push notification,
import notifee from '#notifee/react-native';
notifee.displayNotification({
title: 'New post from John',
body: 'Hey everyone! Check out my new blog post on my website.',
ios: {
categoryId: 'post',
},
});
I want to use sweetalert on my page. The problem is that following the successful operation, the sweetalert appears which is below, and when the OK button is clicked, the page must to be reload (). However, with sweetalert disappears as it appears and the page is reload (). therefore, I don't want the page to be reload () before I click the OK button. What should I do?
Edit Note: I'm using ckeditor on my page. I think the problem stems from ckeditor's editing of textareas. but still i don't know how to solve it.
success: function (response) {
if (response.Result) {
Swal.fire({
title: 'Ok',
text: response.Mesage,
type: 'success',
showCancelButton: false,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ok'
}).then(
function () {
window.location.reload();
}
)
}
else {
Swal.fire(
'Error',
response.Message,
'error')
}
I think it's because your 'then' is firing regardless of the 'result' from the click.
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
window.location.reload(); //i.e. if 'confirm' is pressed
}
})
source: https://sweetalert2.github.io/
after open the notification from notification center, the application running only splash screen and force close after splash screen. my application in android is normal open the alert. my ios version 12.2. my code is here:
initializeApp()
{
this.platform.ready().then(() => {
if (this.platform.is('cordova'))
{
this.oneSignal.startInit('xxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxx');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.handleNotificationReceived().subscribe(data => this.onPushReceived(data.payload));
this.oneSignal.handleNotificationOpened().subscribe(data => this.onPushOpened(data.notification.payload));
this.oneSignal.endInit();
}
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
private onPushOpened(payload: OSNotificationPayload) {
let alert = this.alertCtrl.create({
title: payload.additionalData.nodename,
subTitle: 'My Note : '+payload.additionalData.title1+' <br/> '+'My Why : '+payload.additionalData.mywhy,
message: payload.body,
buttons: [
{
text: 'Utsett',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Det er utført',
handler: () => {
console.log('oke');
this.responseData = result;
this.nav.setRoot(MynotesPage, {id:payload.additionalData.id});
});
}
}
]
});
alert.present();
}
I can't start intent right from "HandleNotificationOpened" function. Can anybody help me with this problem.
MY sencha touch application is working fine in all browsers, however when I save the url to the iPad home screen. It will not load and only shows a blank screen. I get no JS errors and nothing comes through the log when debugging. Heres a sample of the app:
script type="text/javascript">
var rootPanel;
if (navigator.userAgent.match(/iPad/i)) {
viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'width=980');
}
Ext.application({
launch: function () {
var contactForm = Ext.create('Ext.form.FormPanel', {
standardSubmit: true,
fullscreen: true,
items: [{
xtype: 'titlebar',
title: 'My App',
docked: 'top'
}, {
xtype: 'fieldset',
items: [{
xtype: 'textfield',
name: 'LoginName',
label: 'Login Name:'
}, {
xtype: 'passwordfield',
name: 'Password',
label: 'Password:'
},
{
xtype: 'hiddenfield',
name: 'ReturnUrl',
value: '/returnUser.html'
}] // items
}, {
xtype: 'toolbar',
layout: {
pack: 'center'
}, // layout
ui: 'plain',
items: [{
xtype: 'button',
text: 'Reset',
ui: 'decline',
handler: function (btn, evt) {
Ext.Msg.confirm('', 'Are you sure you want to reset this form?', function (btn) {
if (btn === 'yes') {
contactForm.setValues({
LoginName: '',
Password: ''
}); // contactForm()
} // switch
}); // confirm()
}
}, {
xtype: 'button',
text: 'Submit',
ui: 'confirm',
handler: function (btn, evt) {
var values = contactForm.getValues();
contactForm.submit({
url: 'Login',
method: 'POST',
waitTitle: 'Connecting',
waitMsg: 'Sending data...',
success: function (form, result) {
Ext.Msg.alert('Login succeeded!', result.response.reason);
},
failure: function (form, result) {
Ext.Msg.alert('Login Failed!', result.response.reason);
}
});
} // handler
}] // items (toolbar)
}] // items (formpanel)
}); // create()
} // launch
}); // application()
$(document).ready(function () {
});
I put an alert in the launch method of Ext.Application but it does not show. When I put it an alert in the document.ready function it does show. I should also note it DOES work on the ipad browser, just not when launched from the icon on the homescreen.
i faced a similar issue in android actually in my case the problem was because of Ext.Loader not enabled I see you have not included it either. Include this script before Ext.application & see if it works
Ext.Loader.setConfig({
enabled:true
});
Ext.application({...});
It appears to be the version of sencha I was using which was 2.1.0 I believe, as soon as I updated to the latest(2.1.1 Build Date 2013-02-05 12:25:50 ) I works fine.