Files
react-native/Libraries/YellowBox/UI/YellowBoxInspectorHeader.js
T
James Ide 0ee5f68929 Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749)
Summary:
This is the next step in moving RN towards standard path-based requires. All the requires in `Libraries` have been rewritten to use relative requires with a few exceptions, namely, `vendor` and `Renderer/oss` since those need to be changed upstream. This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.

See the umbrella issue at https://github.com/facebook/react-native/issues/24316 for more detail.

[General] [Changed] - Migrate "Libraries" from Haste to standard path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24749

Differential Revision: D15258017

Pulled By: cpojer

fbshipit-source-id: a1f480ea36c05c659b6f37c8f02f6f9216d5a323
2019-05-08 08:48:59 -07:00

119 lines
3.2 KiB
JavaScript

/**
* 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-local
* @format
*/
'use strict';
const Image = require('../../Image/Image');
const Platform = require('../../Utilities/Platform');
const React = require('react');
const SafeAreaView = require('../../Components/SafeAreaView/SafeAreaView');
const StyleSheet = require('../../StyleSheet/StyleSheet');
const Text = require('../../Text/Text');
const View = require('../../Components/View/View');
const YellowBoxImageSource = require('./YellowBoxImageSource');
const YellowBoxPressable = require('./YellowBoxPressable');
const YellowBoxStyle = require('./YellowBoxStyle');
import type YellowBoxWarning from '../Data/YellowBoxWarning';
type Props = $ReadOnly<{|
onSelectIndex: (selectedIndex: number) => void,
selectedIndex: number,
warnings: $ReadOnlyArray<YellowBoxWarning>,
|}>;
const YellowBoxInspectorHeader = (props: Props): React.Node => {
const prevIndex = props.selectedIndex - 1;
const nextIndex = props.selectedIndex + 1;
const titleText =
props.warnings.length === 1
? 'Single Occurrence'
: `Occurrence ${props.selectedIndex + 1} of ${props.warnings.length}`;
return (
<SafeAreaView style={styles.root}>
<View style={styles.header}>
<YellowBoxInspectorHeaderButton
disabled={props.warnings[prevIndex] == null}
image={YellowBoxImageSource.chevronLeft}
onPress={() => props.onSelectIndex(prevIndex)}
/>
<View style={styles.headerTitle}>
<Text style={styles.headerTitleText}>{titleText}</Text>
</View>
<YellowBoxInspectorHeaderButton
disabled={props.warnings[nextIndex] == null}
image={YellowBoxImageSource.chevronRight}
onPress={() => props.onSelectIndex(nextIndex)}
/>
</View>
</SafeAreaView>
);
};
const YellowBoxInspectorHeaderButton = (
props: $ReadOnly<{|
disabled: boolean,
image: string,
onPress?: ?() => void,
|}>,
): React.Node => (
<YellowBoxPressable
backgroundColor={{
default: 'transparent',
pressed: YellowBoxStyle.getHighlightColor(1),
}}
onPress={props.disabled ? null : props.onPress}
style={styles.headerButton}>
{props.disabled ? null : (
<Image
source={{height: 16, uri: props.image, width: 16}}
style={styles.headerButtonImage}
/>
)}
</YellowBoxPressable>
);
const styles = StyleSheet.create({
root: {
backgroundColor: YellowBoxStyle.getBackgroundColor(0.95),
},
header: {
flexDirection: 'row',
height: Platform.select({
android: 48,
ios: 44,
}),
},
headerButton: {
alignItems: 'center',
aspectRatio: 1,
justifyContent: 'center',
},
headerButtonImage: {
tintColor: YellowBoxStyle.getTextColor(1),
},
headerTitle: {
alignItems: 'center',
flex: 1,
justifyContent: 'center',
},
headerTitleText: {
color: YellowBoxStyle.getTextColor(1),
fontSize: 16,
fontWeight: '600',
includeFontPadding: false,
lineHeight: 20,
},
});
module.exports = YellowBoxInspectorHeader;