2017-07-24 16:07:29 -05:00
|
|
|
/* @flow */
|
|
|
|
|
|
2016-10-05 09:36:59 -05:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
2019-04-29 13:37:30 +02:00
|
|
|
import { getFixedPlatformStyle } from '../../styles';
|
|
|
|
|
|
2018-09-13 08:20:22 -07:00
|
|
|
/**
|
2021-11-04 22:10:43 +01:00
|
|
|
* {@code AbstractContainer} Component's property types.
|
2018-09-13 08:20:22 -07:00
|
|
|
*/
|
|
|
|
|
export type Props = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An optional accessibility label to apply to the container root.
|
|
|
|
|
*/
|
|
|
|
|
accessibilityLabel?: string,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not this element is an accessibility element.
|
|
|
|
|
*/
|
|
|
|
|
accessible?: boolean,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* React Elements to display within the component.
|
|
|
|
|
*/
|
2019-03-19 16:42:25 +01:00
|
|
|
children: React$Node,
|
2018-09-13 08:20:22 -07:00
|
|
|
|
2019-08-30 18:39:06 +02:00
|
|
|
/**
|
|
|
|
|
* Class names of the component (for web).
|
|
|
|
|
*/
|
|
|
|
|
className?: string,
|
|
|
|
|
|
2018-09-13 08:20:22 -07:00
|
|
|
/**
|
|
|
|
|
* The event handler/listener to be invoked when this
|
|
|
|
|
* {@code AbstractContainer} is clicked on Web or pressed on React
|
|
|
|
|
* Native. If {@code onClick} is defined and {@link touchFeedback} is
|
|
|
|
|
* undefined, {@code touchFeedback} is considered defined as
|
|
|
|
|
* {@code true}.
|
|
|
|
|
*/
|
|
|
|
|
onClick?: ?Function,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The style (as in stylesheet) to be applied to this
|
|
|
|
|
* {@code AbstractContainer}.
|
|
|
|
|
*/
|
|
|
|
|
style?: Array<?string> | Object,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If this instance is to provide visual feedback when touched, then
|
|
|
|
|
* {@code true}; otherwise, {@code false}. If {@code touchFeedback} is
|
|
|
|
|
* undefined and {@link onClick} is defined, {@code touchFeedback} is
|
|
|
|
|
* considered defined as {@code true}.
|
|
|
|
|
*/
|
|
|
|
|
touchFeedback?: ?Function,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Color to display when clicked.
|
|
|
|
|
*/
|
|
|
|
|
underlayColor?: string,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If this {@code AbstractContainer} is to be visible, then {@code true}
|
|
|
|
|
* or {@code false} if this instance is to be hidden or not rendered at
|
|
|
|
|
* all.
|
|
|
|
|
*/
|
|
|
|
|
visible?: ?boolean
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-05 09:36:59 -05:00
|
|
|
/**
|
2017-07-24 16:07:29 -05:00
|
|
|
* Abstract (base) class for container of React {@link Component} children with
|
|
|
|
|
* a style.
|
2016-10-05 09:36:59 -05:00
|
|
|
*
|
2021-11-04 22:10:43 +01:00
|
|
|
* @augments Component
|
2016-10-05 09:36:59 -05:00
|
|
|
*/
|
2018-09-13 08:20:22 -07:00
|
|
|
export default class AbstractContainer<P: Props> extends Component<P> {
|
2016-10-05 09:36:59 -05:00
|
|
|
/**
|
2017-07-24 16:07:29 -05:00
|
|
|
* Renders this {@code AbstractContainer} as a React {@code Component} of a
|
|
|
|
|
* specific type.
|
2016-10-05 09:36:59 -05:00
|
|
|
*
|
2017-07-24 16:07:29 -05:00
|
|
|
* @param {string|ReactClass} type - The type of the React {@code Component}
|
|
|
|
|
* which is to be rendered.
|
|
|
|
|
* @param {Object|undefined} props - The read-only React {@code Component}
|
2016-10-05 09:36:59 -05:00
|
|
|
* properties, if any, to render. If undefined, the props of this instance
|
|
|
|
|
* will be rendered.
|
|
|
|
|
* @protected
|
|
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
2018-09-13 08:20:22 -07:00
|
|
|
_render(type, props?: P) {
|
2016-10-05 09:36:59 -05:00
|
|
|
const {
|
|
|
|
|
children,
|
2019-04-29 13:37:30 +02:00
|
|
|
style,
|
2016-10-05 09:36:59 -05:00
|
|
|
|
|
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
|
|
|
|
|
// The following properties are defined for the benefit of
|
|
|
|
|
// AbstractContainer and its extenders so they are to not be
|
|
|
|
|
// propagated.
|
|
|
|
|
touchFeedback,
|
|
|
|
|
visible,
|
|
|
|
|
|
|
|
|
|
/* eslint-enable no-unused-vars */
|
|
|
|
|
|
|
|
|
|
...filteredProps
|
|
|
|
|
} = props || this.props;
|
|
|
|
|
|
2019-04-29 13:37:30 +02:00
|
|
|
const _style = getFixedPlatformStyle(style);
|
|
|
|
|
|
2018-10-03 11:29:19 +02:00
|
|
|
// $FlowFixMe
|
2019-04-29 13:37:30 +02:00
|
|
|
return React.createElement(type, {
|
|
|
|
|
style: _style,
|
|
|
|
|
...filteredProps
|
|
|
|
|
}, children);
|
2016-10-05 09:36:59 -05:00
|
|
|
}
|
|
|
|
|
}
|