Skip to content

Commit

Permalink
Register file override.
Browse files Browse the repository at this point in the history
Handle nested text border.
  • Loading branch information
Igor Klemenski committed Aug 26, 2020
1 parent 64f5d81 commit bb7011b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 25 deletions.
7 changes: 7 additions & 0 deletions vnext/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@
"baseHash": "5fe7febd1eb5374745fe612030806512e9161796",
"issue": 5269
},
{
"type": "derived",
"file": "src/Libraries/Text/Text.windows.js",
"baseFile": "Libraries/Text/Text.js",
"baseVersion": "0.0.0-30a89f30c",
"baseHash": "47b5745aff3f5c3fc6f3295e769746b2c40532a6"
},
{
"type": "patch",
"file": "src/Libraries/Types/CoreEventTypes.windows.js",
Expand Down
36 changes: 21 additions & 15 deletions vnext/src/Libraries/Text/Text.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import DeprecatedTextPropTypes from '../DeprecatedPropTypes/DeprecatedTextPropTypes';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text.js';
import TextAncestorBordered from './TextAncestorBordered.windows.js';
import View from '../../Components/View/View';

// [Windows]
Expand All @@ -15,21 +16,26 @@ function BorderedText(props) {

let { style, ...textPropsLessStyle } = props;

if (props.style && props.style.borderWidth &&
props.style.borderColor) {
return (
<>
<View style={props.style}>
<Text style={rest} {...textPropsLessStyle} />
</View>
</>
);
} else {
return (
<>
<Text {...props} />
</>);
}
// Due to XAML limitations, wrapping Text with a View in order to display borders.
// Like other platforms, ignoring borders for nested Text (using the Context API to detect nesting).
return (
<TextAncestorBordered.Consumer>
{
(hasTextAncestor) => hasTextAncestor ?
(<Text {...props} />) :

(props.style && props.style.borderWidth && props.style.borderColor) ?
(<TextAncestorBordered.Provider value={true}>
<View style={props.style}>
<Text style={rest} {...textPropsLessStyle} />
</View>
</TextAncestorBordered.Provider>) :

(<TextAncestorBordered.Provider value={true}>
<Text {...props} />
</TextAncestorBordered.Provider>)
}
</TextAncestorBordered.Consumer>);
}

BorderedText.propTypes = DeprecatedTextPropTypes;
Expand Down
18 changes: 18 additions & 0 deletions vnext/src/Libraries/Text/TextAncestorBordered.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/

'use strict';

const React = require('react');

/**
* Whether the current element is the descendant of a Windows <Text> element.
*/
module.exports = (React.createContext(false): React$Context<$FlowFixMe>);
39 changes: 29 additions & 10 deletions vnext/src/RNTester/js/examples-win/Text/TextExample.windows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,27 @@ export class TextExample extends React.Component<{}> {
</RNTesterBlock>

<RNTesterBlock title="Text With Border">
<Text style={styles.borderStyle}>
This is a piece of text surrounded by a purple border. Forking
components can be a must at times. This is a piece of text
surrounded by a purple border. What a nice piece of bordered text.
This is a piece of text surrounded by a purple border.
</Text>
<>
<Text>
This text is
<Text
style={{color: 'red', borderWidth: 1, borderColor: 'black'}}>
outlined
</Text>
and laid out within the normal text run, so will wrap etc as
normal text.
</Text>

<Text style={styles.borderedText}>
Igor bordered {'\n'}
<Text style={{borderColor: 'red', borderWidth: 5}}>
1st nested - border specifcied but ignored.{'\n'}
<Text style={{borderColor: 'yellow', borderWidth: 4}}>
2nd Inside text!
</Text>
</Text>
</Text>
</>
</RNTesterBlock>
</RNTesterPage>
);
Expand All @@ -616,10 +631,14 @@ export const styles = StyleSheet.create({
textAlignVertical: 'center',
alignSelf: 'center',
},
borderStyle: {
borderWidth: 4,
borderColor: 'purple',
width: 350,
borderedText: {
margin: 100,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
borderWidth: 3,
borderColor: 'green',
padding: 30,
},
});

Expand Down

0 comments on commit bb7011b

Please sign in to comment.