Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25687] Android: Picker change listener doesn't work the first time #9763

Merged
merged 14 commits into from Feb 19, 2018

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Jan 23, 2018

JIRA: https://jira.appcelerator.org/browse/TIMOB-25687

Description:
Set a default preselectedRows pair for NativePicker in order to trigger first time onItemSelect guard.
This would match the default selected item when a index is not set.
That is necessary to not lose the first onItemSelected call in case the adapter is filled for the first time from thread different from the UI one.

Test case:
app.js

var win = Ti.UI.createWindow();
var type2 = [];
type2[0]= Ti.UI.createPickerRow({title: 'Row 1'});
type2[1]= Ti.UI.createPickerRow({title: 'Row 2'});

pickerType = Ti.UI.createPicker();
win.add(pickerType);
setTimeout(loadTypes, 1000);
pickerType.selectionIndicator = true;
pickerType.addEventListener('change', pickerChange);

function loadTypes() {
    pickerType.add(type2);
}

function pickerChange(e){
    alert('Change listener triggered');
}

win.open();

An Alloy test case can be found in the JIRA ticket.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

@jquick-axway
Copy link
Contributor

@ypbnv,
Quick question. Will this also be an issue for pickers with multiple columns?

@ypbnv
Copy link
Contributor Author

ypbnv commented Jan 24, 2018

@jquick-axway Just tested it. It works fine with multiple columns. But I found something else I have missed. I will update once I have it figured out.

@ypbnv
Copy link
Contributor Author

ypbnv commented Jan 24, 2018

@jquick-axway I updated the code. If you could go through the recent changes that would be great.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor change requests.
The rest looks good to me.

public void onItemSelected(AdapterView<?> parent, View view, int position, long itemId)
{
if (!firstSelectedFired) {
final OnItemSelectedListener onItemSelectedListener = new OnItemSelectedListener() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this listener member variable private please?

// swallow the first selected event that gets fired after the adapter gets set, so as to avoid
// firing our change event in that case.
firstSelectedFired = true;
return;
}
fireSelectionChange(0, position);
}*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've removed the firstSelectedFired member variable, we might as well as delete this commented out code block too.

if (p instanceof View) {
((View) p).invalidate();
// Invalidate the parent view after the item is selected (TIMOB-13540).
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_HONEYCOMB) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the HONEYCOMB version check please? Since API Level 16 is the min version we support now, we should always run the below parent invalidate code.

Remove comments left from older code.
Remove outdated platform version check.
@ypbnv
Copy link
Contributor Author

ypbnv commented Jan 25, 2018

@jquick-axway Updated the PR. Also the docs change was made for the previous take on the problem. But it is still relevant because:

  • NativePicker is always used with one column only - the index will always be 0.
  • By default in the Android sources if we do not have preselected index it uses 0 for the dropdown picker.

Should we keep them that way or maybe reword/revert the docs change?

@lokeshchdhry
Copy link
Contributor

@lokeshchdhry
Copy link
Contributor

FR Passed.

The change event is successfully fired for the first time.
Checked with plain picker & multi column picker.

Studio Ver: 5.0.0.201712081732
SDK Ver: 7.1.0 local build
OS Ver: 10.13.2
Xcode Ver: Xcode 9.2
Appc NPM: 4.2.12
Appc CLI: 7.0.2
Daemon Ver: 1.0.1
Ti CLI Ver: 5.0.14
Alloy Ver: 1.11.0
Node Ver: 8.9.1
NPM Ver: 5.5.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 6P --- Android 8.0.0
⇨ google Nexus 5 --- Android 6.0.1

@hansemannn
Copy link
Collaborator

@ypbnv Backport please

@build
Copy link
Contributor

build commented Feb 19, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

@hansemannn hansemannn merged commit 65f161d into tidev:master Feb 19, 2018
@sgtcoolguy sgtcoolguy modified the milestones: 7.2.0, 7.3.0 May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants