Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Zoom/scale setting #1651

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/structures/LoggedInView.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default React.createClass({
return {
// use compact timeline view
useCompactLayout: SettingsStore.getValue('useCompactLayout'),
interfaceScale: SettingsStore.getValue('interfaceScale')
};
},

Expand Down Expand Up @@ -326,7 +327,7 @@ export default React.createClass({
}

return (
<div className='mx_MatrixChat_wrapper'>
<div className='mx_MatrixChat_wrapper' style={{zoom: this.state.interfaceScale + '%'}}>
{ topBar }
<div className={bodyClasses}>
{ SettingsStore.isFeatureEnabled("feature_tag_panel") ? <TagPanel /> : <div /> }
Expand Down
24 changes: 24 additions & 0 deletions src/components/structures/UserSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ module.exports = React.createClass({

this.setState({
language: languageHandler.getCurrentLanguage(),
interfaceScale: SettingsStore.getValue("interfaceScale")
});

this._sessionStore = sessionStore;
Expand Down Expand Up @@ -631,6 +632,17 @@ module.exports = React.createClass({
}
},

onInterfaceScaleChange: function(newInterfaceScale) {
newInterfaceScale = parseInt(newInterfaceScale);
if (this.state.interfaceScale !== newInterfaceScale) {
SettingsStore.setValue("interfaceScale", null, SettingLevel.DEVICE, newInterfaceScale);
this.setState({
interfaceScale: newInterfaceScale,
});
PlatformPeg.get().reload();
Copy link
Member

Choose a reason for hiding this comment

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

Changing scale yielding a full reload is really bad UX :(

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Just a copy from language setting to start with. What would you prefer happen? Options:

  1. Note that zoom will apply after a restart of the app
  2. Zoom as the setting is changed - might be buggy because of scaling happening while the user is touching controls
  3. Zoom with a delay?

If 2 is preferable, is there a way in this sdk to watch a state change (scale changing) on the root element? Maybe SettingsManager has a watch function? Or is the only way to bubble up the change through the component tree?

Copy link
Member

@t3chguy t3chguy Dec 7, 2017

Choose a reason for hiding this comment

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

you could use the dispatcher to send a zoom_change event that LoggedInView/MatrixChat listens on and acts on when you save the setting

}
},

_renderLanguageSetting: function() {
const LanguageDropdown = sdk.getComponent('views.elements.LanguageDropdown');
return <div>
Expand All @@ -642,6 +654,17 @@ module.exports = React.createClass({
</div>;
},

_renderInterfaceScaleSetting: function() {
const InterfaceScaleSlider = sdk.getComponent('views.elements.InterfaceScaleSlider');
return <div>
<label htmlFor="interfaceScaleSelector">{ _t('Interface Scale') }</label>
<InterfaceScaleSlider ref="interfaceScaleSelector" onValueChange={this.onInterfaceScaleChange}
className="mx_UserSettings_scale"
value={this.state.interfaceScale}
/>
</div>;
},

_renderUserInterfaceSettings: function() {
// TODO: this ought to be a separate component so that we don't need
// to rebind the onChange each time we render
Expand All @@ -668,6 +691,7 @@ module.exports = React.createClass({
</tbody>
</table>
{ this._renderLanguageSetting() }
{ this._renderInterfaceScaleSetting() }
</div>
</div>
);
Expand Down
51 changes: 51 additions & 0 deletions src/components/views/elements/InterfaceScaleSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2017 Marcel Radzio (MTRNord)
Copyright 2017 Vector Creations Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

^^ this needs fixing

Copy link
Author

Choose a reason for hiding this comment

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

What should this be changed to? This was a copy from another component. Should I be putting it under my own name?

Copy link
Member

Choose a reason for hiding this comment

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

Yup, unless someone else wrote it :P

Copy link
Author

Choose a reason for hiding this comment

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

ok 😄 and also remove Copyright 2017 Vector Creations?

Copy link
Member

Choose a reason for hiding this comment

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

yup :)

Copy link
Author

Choose a reason for hiding this comment

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

done 😃 hope my name is not taking too much space in the repo


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';

import sdk from '../../../index';
import SettingsStore from "../../../settings/SettingsStore";

export default class InterfaceScaleSlider extends React.Component {
constructor(props) {
super(props);
this._onValueChange = this._onValueChange.bind(this);
}

componentWillMount() {
Copy link
Member

Choose a reason for hiding this comment

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

no point having an empty willMount

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about the goofs 🙂 updated those now

}

_onValueChange(e) {
this.props.onValueChange(parseInt(e.target.value));
}

render() {
let interfaceScale = SettingsStore.getValue("interfaceScale", null, /*excludeDefault:*/true);
let value = this.props.value || interfaceScale;
return <div>
<input type="range" min="50" max="150" step="25" className={this.props.className}
onChange={this._onValueChange} value={value} />
{value}%
</div>
}
}

InterfaceScaleSlider.propTypes = {
Copy link
Member

Choose a reason for hiding this comment

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

this can be moved into the body of the class as

static propTypes = {
...
};

className: React.PropTypes.string,
onValueChange: React.PropTypes.func.isRequired,
value: React.PropTypes.number,
};
4 changes: 4 additions & 0 deletions src/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export const SETTINGS = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: "en",
},
"interfaceScale": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: 100,
},
"analyticsOptOut": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td('Opt out of analytics'),
Expand Down