Files
Mateo GuzmánandFacebook GitHub Bot e39776b1b8 Fix Alert and SafeAreaView examples in dark mode (#48752)
Summary:
Fix Alert and SafeAreaView examples in dark mode. Converting also SafeAreaView examples into functional components

## Changelog:

[INTERNAL] - Fix Alert and SafeAreaView examples in dark mode

Pull Request resolved: https://github.com/facebook/react-native/pull/48752

Test Plan:
<details>
<summary>Screenshots</summary>

| After | Before |
|--------|-------|
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-01-16 at 18 10 12](https://github.com/user-attachments/assets/9cbe4403-47bd-452a-9b36-a75a24f792e4) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-01-16 at 18 09 47](https://github.com/user-attachments/assets/47706394-f394-4a3e-936c-da2f0716a274) |
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-01-16 at 18 07 31](https://github.com/user-attachments/assets/5835e4f9-7f5e-4a9d-963d-501a1a577da7) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-01-16 at 15 20 26](https://github.com/user-attachments/assets/d9ff678f-dce3-4684-9a15-bf11c2bab4bd) |

</details>

Reviewed By: cortinico

Differential Revision: D68322518

Pulled By: rshest

fbshipit-source-id: 9f153862efff7ef1e834bac9843f4042dbefbd1b
2025-01-17 06:20:53 -08:00

107 lines
2.8 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and 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 RNTesterText from '../../components/RNTesterText';
import React from 'react';
import {
Button,
DeviceInfo,
Modal,
SafeAreaView,
StyleSheet,
View,
} from 'react-native';
function SafeAreaViewExample(): React.Node {
const [modalVisible, setModalVisible] = React.useState<boolean>(false);
const toggleModal = (visible: boolean) => {
setModalVisible(visible);
};
return (
<View>
<Modal
visible={modalVisible}
onRequestClose={() => toggleModal(false)}
animationType="slide"
supportedOrientations={['portrait', 'landscape']}>
<View style={styles.modal}>
<SafeAreaView style={styles.safeArea}>
<View style={styles.safeAreaContent}>
<Button onPress={() => toggleModal(false)} title="Close" />
</View>
</SafeAreaView>
</View>
</Modal>
<Button
onPress={() => toggleModal(true)}
title="Present Modal Screen with SafeAreaView"
/>
</View>
);
}
function IsIPhoneXExample(): React.Node {
return (
<View>
<RNTesterText>
Is this an iPhone X:{' '}
{DeviceInfo.getConstants()?.isIPhoneX_deprecated === true
? 'Yeah!'
: 'Nope. (Or `isIPhoneX_deprecated` was already removed.)'}
</RNTesterText>
</View>
);
}
const styles = StyleSheet.create({
modal: {
flex: 1,
},
safeArea: {
flex: 1,
height: 1000,
},
safeAreaContent: {
flex: 1,
backgroundColor: '#ffaaaa',
alignItems: 'center',
justifyContent: 'center',
},
});
exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = 'SafeAreaView';
exports.category = 'UI';
exports.documentationURL = 'https://reactnative.dev/docs/safeareaview';
exports.description =
'SafeAreaView automatically applies paddings reflect the portion of the view that is not covered by other (special) ancestor views.';
exports.examples = [
{
title: '<SafeAreaView> Example',
description:
'SafeAreaView automatically applies paddings reflect the portion of the view that is not covered by other (special) ancestor views.',
render: (): React.Node => <SafeAreaViewExample />,
},
{
title: 'isIPhoneX_deprecated Example',
description:
('`DeviceInfo.isIPhoneX_deprecated` returns true only on iPhone X. ' +
'Note: This prop is deprecated and will be removed in a future ' +
'release. Please use this only for a quick and temporary solution. ' +
'Use <SafeAreaView> instead.': string),
render: (): React.Node => <IsIPhoneXExample />,
},
];