Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 1216432 - Fix emoji swipe panel layout in landscape mode, r=timdream #33490

Merged
merged 1 commit into from Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/keyboard/js/views/swipeable_page_view.js
Expand Up @@ -31,6 +31,8 @@ SwipeablePageView.prototype.render = function() {
this.viewManager);
swipeablePanel.render();

this.swipeablePanel = swipeablePanel;

container.appendChild(swipeablePanel.element);

// Render the bottom row for switching different type of emojis
Expand Down Expand Up @@ -73,6 +75,11 @@ SwipeablePageView.prototype.render = function() {
this.element = container;
};

SwipeablePageView.prototype.resize = function resize(totalWidth) {
this.options.totalWidth = totalWidth;
this.swipeablePanel.resize(totalWidth);
};

SwipeablePageView.prototype.getHeight = function() {
return this.element.clientHeight;
};
Expand Down
31 changes: 30 additions & 1 deletion apps/keyboard/js/views/swipeable_panel_view.js
Expand Up @@ -105,6 +105,27 @@ SwipeablePanelView.prototype.gotoSection = function(index) {
this._updateIndicator();
};

SwipeablePanelView.prototype.resize = function resize(totalWidth) {
this.options.totalWidth = totalWidth;
this.swipeDetectingPaused = true;

// Reposition sections when resize;
this.sections.forEach(function(section, index) {
var translateX;

if (index === this.currentSectionIndex) {
translateX = 0;
} else if (this.currentSectionIndex > index) {
translateX = -totalWidth;
} else {
translateX = totalWidth;
}

section.style.transform = 'translateX(' + translateX + 'px)';
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user has her/his finger swiping while rotate the phone? Is it possible to address that too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, now resize function could not handle this issue. It's not easy to reproduce, but goes wrong while swiping and rotating at the specific timing. I think it might be sort of race condition between events, and I'm on it :)

}, this);

};

SwipeablePanelView.prototype._moveSection = function(index, distance) {
var style = this.sections[index].style;
style.transform = 'translateX(' + distance + 'px)';
Expand All @@ -122,9 +143,14 @@ SwipeablePanelView.prototype._updateIndicator = function() {
SwipeablePanelView.prototype._handleTouchStart = function(evt) {
this.startX = evt.position.clientX;
this.deltaX = 0;
this.swipeDetectingPaused = false;
};

SwipeablePanelView.prototype._handlePan = function(evt) {
if (this.swipeDetectingPaused) {
return;
}

var totalWidth = this.options.totalWidth;

// Clear all transition styles
Expand Down Expand Up @@ -184,8 +210,11 @@ SwipeablePanelView.prototype._handlePan = function(evt) {
};

SwipeablePanelView.prototype._handleSwipe = function(evt) {
var totalWidth = this.options.totalWidth;
if (this.swipeDetectingPaused) {
return;
}

var totalWidth = this.options.totalWidth;
var targetIndex = this.currentSectionIndex;
var forward = evt.direction === 'left';

Expand Down
2 changes: 1 addition & 1 deletion apps/keyboard/style/keyboard.css
Expand Up @@ -833,7 +833,7 @@ bubble above the key when you tap and hold. */
background: none;
font-size: 3rem;
min-height: 5rem;
min-width: 5rem;
min-width: 16.66vw;
padding: 0;
flex: 1;
}
Expand Down
46 changes: 46 additions & 0 deletions apps/keyboard/test/unit/views/swipeable_panel_view_test.js
Expand Up @@ -346,4 +346,50 @@ suite('Views > SwipeablePanelView', function() {
assert.equal(panelView.sections[1].style.transform, 'translateX(320px)');
});
});

suite('rotate', function() {
var rootElement = document.createElement('div');

setup(function() {
document.body.appendChild(rootElement);
var options = { totalWidth: 320 };

panelView = new SwipeablePanelView(layout, options,
viewManager);

panelView.render();
});

teardown(function() {
rootElement.innerHTML = '';
});

test('> rotate to landscape - at first section', function() {
panelView.resize(590);

assert.equal(panelView.sections[0].style.transform, 'translateX(0px)');
assert.equal(panelView.sections[1].style.transform, 'translateX(590px)');
});

test('> rotate to landscape - at second section', function() {
panelView.gotoSection(1);
panelView.resize(590);

assert.equal(panelView.sections[0].style.transform, 'translateX(-590px)');
assert.equal(panelView.sections[1].style.transform, 'translateX(0px)');
assert.equal(panelView.sections[2].style.transform, 'translateX(590px)');
});

test('> rotate to landscape - at last section', function() {
panelView.gotoSection(sectionCount - 1);
panelView.resize(590);

assert.equal(
panelView.sections[sectionCount - 1].style.transform,
'translateX(0px)');
assert.equal(
panelView.sections[sectionCount - 2].style.transform,
'translateX(-590px)');
});
});
});