mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1c634a9218
Summary: Refs https://github.com/facebook/react-native/issues/28711 This PR moves Hermes badge component from the template to the `NewAppScreen` library. The main motivation behind this change was to simplify a bit template code. I assumed that it is not important to expose `global.HermesInternal` to the template users: * If this assumption is true, I think that there are no other reason to leave this component inside `App` in comparison to other `NewAppScreen` components, * If this assumption is false, I can adjust this PR and move `HermesInternal` check from the badge component to the `App`. I was trying to avoid calling `useColorScheme` when Hermes is disabled, but placing hook inside the conditional branch causes ESLint warning (react-hooks/rules-of-hooks). This PR includes also small style tweaks for the badge - since there are no background padding can be omitted and spacing can be added adjusted tweaking `top` and `left` properties and `fontSize` has been adjusted just for the readability. In the last commit, I have gone a bit further and moved `HermesBadge` to the `Header` component and I have also changed slightly the `Header` title (React -> React Native) and it's styling. > I'm not sure if after this change `HermesBadge` export in `NewAppScreen` components list is still required, but maybe this badge will be useful for someone. If it's a mistake I can update the PR and remove this export. ## Changelog [Internal][Changed] move Hermes badge from the template to the NewAppScreen library Pull Request resolved: https://github.com/facebook/react-native/pull/28783 Test Plan: Template app do not redbox on Android emulator with and without Hermes enabled. ## Preview Android with Hermes enabled and adjusted header:  iOS with adjusted header:  Reviewed By: GijsWeterings Differential Revision: D22493822 Pulled By: cpojer fbshipit-source-id: 3440e10f2d59f268ca8851a6e002f0ff23fa839c
74 lines
1.7 KiB
JavaScript
74 lines
1.7 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';
|
|
import type {Node} from 'react';
|
|
import {ImageBackground, StyleSheet, Text, useColorScheme} from 'react-native';
|
|
import React from 'react';
|
|
import Colors from './Colors';
|
|
import HermesBadge from './HermesBadge';
|
|
|
|
const Header = (): Node => {
|
|
const isDarkMode = useColorScheme() === 'dark';
|
|
return (
|
|
<ImageBackground
|
|
accessibilityRole="image"
|
|
source={require('./logo.png')}
|
|
style={[
|
|
styles.background,
|
|
{
|
|
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
|
|
},
|
|
]}
|
|
imageStyle={styles.logo}>
|
|
<HermesBadge />
|
|
<Text
|
|
style={[
|
|
styles.text,
|
|
{
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
},
|
|
]}>
|
|
Welcome to
|
|
{'\n'}
|
|
React Native
|
|
</Text>
|
|
</ImageBackground>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
background: {
|
|
paddingBottom: 40,
|
|
paddingTop: 96,
|
|
paddingHorizontal: 32,
|
|
},
|
|
logo: {
|
|
opacity: 0.2,
|
|
overflow: 'visible',
|
|
resizeMode: 'cover',
|
|
/*
|
|
* These negative margins allow the image to be offset similarly across screen sizes and component sizes.
|
|
*
|
|
* The source logo.png image is 512x512px, so as such, these margins attempt to be relative to the
|
|
* source image's size.
|
|
*/
|
|
marginLeft: -128,
|
|
marginBottom: -192,
|
|
},
|
|
text: {
|
|
fontSize: 40,
|
|
fontWeight: '700',
|
|
textAlign: 'center',
|
|
},
|
|
});
|
|
|
|
export default Header;
|