mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-31 17:53:50 +00:00
[add] Text support for inline View and Image
When 'View' or 'Image' are within a 'Text', lay them out as 'inline-flex'. Fix #472
This commit is contained in:
@@ -48,6 +48,7 @@ input::-webkit-inner-spin-button,input::-webkit-outer-spin-button,input::-webkit
|
|||||||
.rn-borderLeftWidth-gxnn5r{border-left-width:0px}
|
.rn-borderLeftWidth-gxnn5r{border-left-width:0px}
|
||||||
.rn-boxSizing-deolkf{box-sizing:border-box}
|
.rn-boxSizing-deolkf{box-sizing:border-box}
|
||||||
.rn-display-6koalj{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex}
|
.rn-display-6koalj{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex}
|
||||||
|
.rn-display-xoduu5{display:-webkit-box;display:-moz-box;display:-ms-inline-flexbox;display:-webkit-inline-flex;display:inline-flex}
|
||||||
.rn-flexShrink-1qe8dj5{-webkit-flex-shrink:0;flex-shrink:0}
|
.rn-flexShrink-1qe8dj5{-webkit-flex-shrink:0;flex-shrink:0}
|
||||||
.rn-flexShrink-1wbh5a2{-webkit-flex-shrink:1;flex-shrink:1}
|
.rn-flexShrink-1wbh5a2{-webkit-flex-shrink:1;flex-shrink:1}
|
||||||
.rn-flexBasis-1mlwlqe{-webkit-flex-basis:auto;flex-basis:auto}
|
.rn-flexBasis-1mlwlqe{-webkit-flex-basis:auto;flex-basis:auto}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import StyleSheet from '../../apis/StyleSheet';
|
|||||||
import StyleSheetPropType from '../../propTypes/StyleSheetPropType';
|
import StyleSheetPropType from '../../propTypes/StyleSheetPropType';
|
||||||
import View from '../View';
|
import View from '../View';
|
||||||
import ViewPropTypes from '../View/ViewPropTypes';
|
import ViewPropTypes from '../View/ViewPropTypes';
|
||||||
import { any, func, number, oneOf, oneOfType, shape, string } from 'prop-types';
|
import { any, bool, func, number, oneOf, oneOfType, shape, string } from 'prop-types';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
const emptyObject = {};
|
const emptyObject = {};
|
||||||
@@ -63,6 +63,10 @@ class Image extends Component {
|
|||||||
|
|
||||||
static displayName = 'Image';
|
static displayName = 'Image';
|
||||||
|
|
||||||
|
static contextTypes = {
|
||||||
|
isInAParentText: bool
|
||||||
|
};
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
...ViewPropTypes,
|
...ViewPropTypes,
|
||||||
children: any,
|
children: any,
|
||||||
@@ -167,6 +171,7 @@ class Image extends Component {
|
|||||||
imageSizeStyle,
|
imageSizeStyle,
|
||||||
originalStyle,
|
originalStyle,
|
||||||
resizeModeStyles[finalResizeMode],
|
resizeModeStyles[finalResizeMode],
|
||||||
|
this.context.isInAParentText && styles.inline,
|
||||||
backgroundImage && { backgroundImage }
|
backgroundImage && { backgroundImage }
|
||||||
]);
|
]);
|
||||||
// View doesn't support 'resizeMode' as a style
|
// View doesn't support 'resizeMode' as a style
|
||||||
@@ -276,6 +281,9 @@ const styles = StyleSheet.create({
|
|||||||
backgroundSize: 'cover',
|
backgroundSize: 'cover',
|
||||||
zIndex: 0
|
zIndex: 0
|
||||||
},
|
},
|
||||||
|
inline: {
|
||||||
|
display: 'inline-flex'
|
||||||
|
},
|
||||||
img: {
|
img: {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
|
|||||||
@@ -27,16 +27,17 @@ const calculateHitSlopStyle = hitSlop => {
|
|||||||
class View extends Component {
|
class View extends Component {
|
||||||
static displayName = 'View';
|
static displayName = 'View';
|
||||||
|
|
||||||
static propTypes = ViewPropTypes;
|
|
||||||
|
|
||||||
static childContextTypes = {
|
static childContextTypes = {
|
||||||
isInAButtonView: bool
|
isInAButtonView: bool
|
||||||
};
|
};
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
isInAButtonView: bool
|
isInAButtonView: bool,
|
||||||
|
isInAParentText: bool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static propTypes = ViewPropTypes;
|
||||||
|
|
||||||
getChildContext() {
|
getChildContext() {
|
||||||
const isInAButtonView =
|
const isInAButtonView =
|
||||||
AccessibilityUtil.propsToAriaRole(this.props) === 'button' || this.context.isInAButtonView;
|
AccessibilityUtil.propsToAriaRole(this.props) === 'button' || this.context.isInAButtonView;
|
||||||
@@ -57,9 +58,9 @@ class View extends Component {
|
|||||||
...otherProps
|
...otherProps
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const { isInAButtonView } = this.context;
|
const { isInAButtonView, isInAParentText } = this.context;
|
||||||
|
|
||||||
otherProps.style = [styles.initial, style];
|
otherProps.style = [styles.initial, isInAParentText && styles.inline, style];
|
||||||
|
|
||||||
if (hitSlop) {
|
if (hitSlop) {
|
||||||
const hitSlopStyle = calculateHitSlopStyle(hitSlop);
|
const hitSlopStyle = calculateHitSlopStyle(hitSlop);
|
||||||
@@ -91,6 +92,9 @@ const styles = StyleSheet.create({
|
|||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
minWidth: 0
|
minWidth: 0
|
||||||
},
|
},
|
||||||
|
inline: {
|
||||||
|
display: 'inline-flex'
|
||||||
|
},
|
||||||
// this zIndex ordering positions the hitSlop above the View but behind
|
// this zIndex ordering positions the hitSlop above the View but behind
|
||||||
// its children
|
// its children
|
||||||
hasHitSlop: {
|
hasHitSlop: {
|
||||||
|
|||||||
Reference in New Issue
Block a user