Skip to content

Commit

Permalink
Without formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KeKs0r committed May 9, 2019
1 parent d519754 commit 198d8c3
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions src/Focusable.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Focusable extends Component {
treePath = [];
Expand All @@ -12,7 +12,7 @@ class Focusable extends Component {

state = {
focusTo: null
};
}

constructor(props, context) {
super(props, context);
Expand All @@ -21,7 +21,7 @@ class Focusable extends Component {
isContainer() {
return false;
}

hasChildren() {
return this.children.length > 0;
}
Expand All @@ -38,15 +38,14 @@ class Focusable extends Component {
removeChild(child) {
this.context.navigationComponent.removeFocusableId(child.focusableId);

const currentFocusedPath = this.context.navigationComponent
.currentFocusedPath;
if (!currentFocusedPath) {
return;
const currentFocusedPath = this.context.navigationComponent.currentFocusedPath;
if(!currentFocusedPath){
return
}
const index = currentFocusedPath.indexOf(child);

if (index > 0) {
this.setState({ focusTo: currentFocusedPath[index - 1] });
this.setState({ focusTo: currentFocusedPath[index - 1] })
}
}

Expand Down Expand Up @@ -75,7 +74,7 @@ class Focusable extends Component {
if (this.hasChildren()) {
return this.children[this.getDefaultChild()].getDefaultFocus();
}

return null;
}

Expand All @@ -95,10 +94,7 @@ class Focusable extends Component {
focus() {
this.treePath.map(component => {
if (component.props.onFocus)
component.props.onFocus(
this.indexInParent,
this.context.navigationComponent
);
component.props.onFocus(this.indexInParent, this.context.navigationComponent);
});
}

Expand Down Expand Up @@ -134,11 +130,8 @@ class Focusable extends Component {
}

componentDidMount() {
this.focusableId = this.context.navigationComponent.addComponent(
this,
this.props.focusId
);

this.focusableId = this.context.navigationComponent.addComponent(this, this.props.focusId);

if (this.context.parentFocusable) {
this.buildTreePath();
this.indexInParent = this.getParent().addChild(this);
Expand All @@ -157,7 +150,7 @@ class Focusable extends Component {
if (this.context.parentFocusable) {
this.getParent().removeChild(this);
}

this.focusableId = null;
}

Expand All @@ -173,44 +166,32 @@ class Focusable extends Component {
}

if (this.state.focusTo !== null) {
this.context.navigationComponent.focus(
this.state.focusTo.getDefaultFocus()
);
this.context.navigationComponent.focus(this.state.focusTo.getDefaultFocus());
this.setState({ focusTo: null });
}

this.updateChildrenOrder = false;
}

render() {
const {
focusId,
rootNode,
navDefault,
forceFocus,
retainLastFocus,
onFocus,
onBlur,
onEnterDown,
...props
} = this.props;
const { focusId, rootNode, navDefault, forceFocus, retainLastFocus, onFocus, onBlur, onEnterDown, ...props } = this.props;

if (this.children.length > 0) {
this.updateChildrenOrder = true;
this.updateChildrenOrderNum = 0;
}

return <span {...props} />;
return <span {...props} />
}
}

Focusable.contextTypes = {
parentFocusable: PropTypes.object,
navigationComponent: PropTypes.object
navigationComponent: PropTypes.object,
};

Focusable.childContextTypes = {
parentFocusable: PropTypes.object
parentFocusable: PropTypes.object,
};

Focusable.defaultProps = {
Expand Down

0 comments on commit 198d8c3

Please sign in to comment.