#26: add a method to request panel height measurement from child components

This commit is contained in:
SleepWalker 2016-05-22 16:07:51 +03:00
parent a9efb9040a
commit 291a498f19
3 changed files with 16 additions and 8 deletions

View File

@ -11,6 +11,7 @@ export default class BaseAuthBody extends Component {
static contextTypes = {
clearErrors: PropTypes.func.isRequired,
resolve: PropTypes.func.isRequired,
requestRedraw: PropTypes.func.isRequired,
auth: PropTypes.shape({
error: PropTypes.string,
scopes: PropTypes.array

View File

@ -89,6 +89,7 @@ class PanelTransition extends Component {
})
}),
user: userShape,
requestRedraw: PropTypes.func,
clearErrors: PropTypes.func,
resolve: PropTypes.func,
reject: PropTypes.func
@ -103,6 +104,7 @@ class PanelTransition extends Component {
return {
auth: this.props.auth,
user: this.props.user,
requestRedraw: () => this.setState({isHeightDirty: true}, () => this.setState({isHeightDirty: false})),
clearErrors: this.props.clearErrors,
resolve: this.props.resolve,
reject: this.props.reject
@ -196,7 +198,7 @@ class PanelTransition extends Component {
</PanelHeader>
<div style={contentHeight}>
<MeasureHeight
state={this.props.auth.error}
state={this.shouldMeasureHeight()}
onMeasure={this.onUpdateContextHeight}
>
<PanelBody>
@ -307,6 +309,10 @@ class PanelTransition extends Component {
}
}
shouldMeasureHeight() {
return '' + this.props.auth.error + this.state.isHeightDirty;
}
getHeader({key, style, data}) {
const {Title, hasBackButton} = data;
const {transformSpring} = style;
@ -363,7 +369,7 @@ class PanelTransition extends Component {
<MeasureHeight
key={`body/${key}`}
style={style}
state={this.props.auth.error}
state={this.shouldMeasureHeight()}
onMeasure={(height) => this.onUpdateHeight(height, key)}
>
{React.cloneElement(Body, {

View File

@ -20,12 +20,6 @@ export default class ForgotPasswordBody extends BaseAuthBody {
autoFocusField = this.state.isLoginEdit ? 'email' : null;
onClickEdit = () => {
this.setState({
isLoginEdit: true
});
};
render() {
const { user } = this.context;
const login = user.email || user.username || '';
@ -68,4 +62,11 @@ export default class ForgotPasswordBody extends BaseAuthBody {
</div>
);
}
onClickEdit = () => {
this.setState({
isLoginEdit: true
});
this.context.requestRedraw();
};
}