Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28448] Android: Ti.UI.Notifications logs errors because of alignment, margins and gravity

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2021-05-24T15:35:49.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.1
ComponentsAndroid
Labelsandroid, error, log, notifications, toast
ReporterHans Knöchel
AssigneeJoshua Quick
Created2021-05-14T13:17:13.000+0000
Updated2021-05-24T15:35:49.000+0000

Description

When showing a Ti.UI.Notification, the console always logs an error since a few Android versions (mostly noted since Android 11):
[ERROR] Toast: getHorizontalMargin() shouldn't be called on text toasts, the result may not reflect actual values.
[ERROR] Toast: getVerticalMargin() shouldn't be called on text toasts, the result may not reflect actual values.
[ERROR] Toast: getXOffset() shouldn't be called on text toasts, the result may not reflect actual values.
[ERROR] Toast: getYOffset() shouldn't be called on text toasts, the result may not reflect actual values.
[ERROR] Toast: getGravity() shouldn't be called on text toasts, the result may not reflect actual values.
[ERROR] Toast: setMargin() shouldn't be called on text toasts, the values won't be used
[ERROR] Toast: setGravity() shouldn't be called on text toasts, the values won't be used
The issue can be fixed by guarding the related properties to only access them if we really want to override alignment, gravity or margins. Test case:
const window = Ti.UI.createWindow();
window.addEventListener('open', () => {
    Ti.UI.createNotification({
        title: 'Hello world',
        duration: Ti.UI.NOTIFICATION_DURATION_SHORT
    }).show();
});
window.open();

Comments

  1. Hans Knöchel 2021-05-14

    PR: https://github.com/appcelerator/titanium_mobile/pull/12815
  2. Christopher Williams 2021-05-24

    merged to master and 10_0_X branch for 10.0.1 target

JSON Source