Skip to content

Commit

Permalink
[Fabric] Get Modal to host RN components in new hwnd (#13500)
Browse files Browse the repository at this point in the history
* save state

* add example

* build but blank page still :(

* clean up comments

* visuals show up in new hwnd!

* clean up code

* better naming and unfork Modal examples

* testing save state

* Make the RN island a Modal member var

* Failed attempt at skipping root view in CEH, leaving it for learning purposes

* you can click on UI!

* clean up code

* Change files

* save state

* remove hardcoded rootTag

* add width/height to example

* add test

* revert simple.tsx

* remove test

* update snapshot

* feedback part 1: make Modal a RootComponentView

* feedback part2: simplify MountChildren

* fix deleting modal

* feedback round2

* remove comment

* remove imports

* feedback part 3

* fix overrides

* add simple layout - still has issues with padding/flex

* feedback part4

* lint

* update overrides

* Change files

* feedback

---------

Co-authored-by: Daniel Ayala <[email protected]>
  • Loading branch information
TatianaKapos and danielayala94 authored Nov 1, 2024
1 parent dc70ca2 commit 15e5afb
Show file tree
Hide file tree
Showing 22 changed files with 2,293 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "adds default Modal",
"packageName": "@office-iss/react-native-win32",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "adds default modal that hosts fabric components",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const Components: Array<RNTesterModuleInfo> = [
key: 'ImageWin32Test',
module: require('@office-iss/react-native-win32/Libraries/Image/Tests/ImageWin32Test'),
},
{
key: 'ModalExample',
category: 'UI',
module: require('../examples/Modal/ModalExample'),
},
/*
{
key: 'JSResponderHandlerExample',
Expand All @@ -68,11 +73,6 @@ const Components: Array<RNTesterModuleInfo> = [
key: 'KeyboardAvoidingViewExample',
module: require('../examples/KeyboardAvoidingView/KeyboardAvoidingViewExample'),
},
{
key: 'ModalExample',
category: 'UI',
module: require('../examples/Modal/ModalExample'),
},
{
key: 'NewAppScreenExample',
module: require('../examples/NewAppScreen/NewAppScreenExample'),
Expand Down
12 changes: 6 additions & 6 deletions packages/@office-iss/react-native-win32/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@
"baseHash": "bc63f57b28f1e98755101f650a2c15b6aa263abf",
"issue": 11041
},
{
"type": "copy",
"file": "src-win/src/private/reactdevtools/ReactDevToolsSettingsManager.win32.js",
"baseFile": "packages/react-native/src/private/reactdevtools/ReactDevToolsSettingsManager.android.js",
"baseHash": "df41b76dc3d2df9455fae588748261d7b0a22d01"
},
{
"type": "derived",
"file": "src-win/src/private/specs/modules/NativeAccessibilityInfoWin32.js",
Expand All @@ -523,12 +529,6 @@
"file": "src-win/src/private/specs/modules/NativePlatformConstantsWin.js",
"baseFile": "packages/react-native/src/private/specs/modules/NativePlatformConstantsAndroid.js",
"baseHash": "fa0f34a2de33b641bd63863629087644796d8b59"
},
{
"type": "copy",
"file": "src-win/src/private/reactdevtools/ReactDevToolsSettingsManager.win32.js",
"baseFile": "packages/react-native/src/private/reactdevtools/ReactDevToolsSettingsManager.android.js",
"baseHash": "df41b76dc3d2df9455fae588748261d7b0a22d01"
}
]
}
12 changes: 12 additions & 0 deletions packages/@react-native-windows/tester/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
"baseHash": "eb640e1c484a8cdaa04d653505d5aab6429eb4b0",
"issue": 12869
},
{
"type": "patch",
"file": "src/js/examples/Modal/ModalOnShow.windows.js",
"baseFile": "packages/rn-tester/js/examples/Modal/ModalOnShow.js",
"baseHash": "d442625a5c03de1ea78a43385c8f60dd9b4da68c"
},
{
"type": "patch",
"file": "src/js/examples/Modal/ModalPresentation.windows.js",
"baseFile": "packages/rn-tester/js/examples/Modal/ModalPresentation.js",
"baseHash": "1e3d81c2a1f6e5a05747244a4efd18548d88051d"
},
{
"type": "patch",
"file": "src/js/examples/Pressable/PressableExample.windows.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* 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
*/

import type {RNTesterModuleExample} from '../../types/RNTesterTypes';

import * as React from 'react';
import {Modal, Pressable, StyleSheet, Text, View} from 'react-native';

function ModalOnShowOnDismiss(): React.Node {
const [modalShowComponent, setModalShowComponent] = React.useState(true);
const [modalVisible, setModalVisible] = React.useState(false);
const [onShowCount, setOnShowCount] = React.useState(0);
const [onDismissCount, setOnDismissCount] = React.useState(0);

return (
<View style={styles.container}>
{modalShowComponent && (
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onShow={() => {
setOnShowCount(onShowCount + 1);
}}
onDismiss={() => {
setOnDismissCount(onDismissCount + 1);
}}
onRequestClose={() => {
setModalVisible(false);
}}>
<View
style={[
styles.centeredView,
styles.modalBackdrop,
styles.widthHeight,
]}>
<View style={styles.modalView}>
<Text testID="modal-on-show-count">
onShow is called {onShowCount} times
</Text>
<Text testID="modal-on-dismiss-count">
onDismiss is called {onDismissCount} times
</Text>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(false)}>
<Text testID="dismiss-modal" style={styles.textStyle}>
Hide modal by setting visible to false
</Text>
</Pressable>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalShowComponent(false)}>
<Text
testID="dismiss-modal-by-removing-component"
style={styles.textStyle}>
Hide modal by removing component
</Text>
</Pressable>
</View>
</View>
</Modal>
)}
<Text testID="on-show-count">onShow is called {onShowCount} times</Text>
<Text testID="on-dismiss-count">
onDismiss is called {onDismissCount} times
</Text>
<Pressable
style={[styles.button, styles.buttonOpen]}
onPress={() => {
setModalShowComponent(true);
setModalVisible(true);
}}>
<Text testID="open-modal" style={styles.textStyle}>
Show Modal
</Text>
</Pressable>
</View>
);
}

const styles = StyleSheet.create({
container: {
display: 'flex',
alignItems: 'center',
paddingVertical: 30,
},
centeredView: {
// flex: 1, [Windows]
justifyContent: 'center',
alignItems: 'center',
},
modalBackdrop: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modalView: {
margin: 20,
backgroundColor: 'white',
borderRadius: 20,
padding: 35,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
button: {
borderRadius: 20,
padding: 10,
marginVertical: 20,
elevation: 2,
},
buttonOpen: {
backgroundColor: '#F194FF',
},
buttonClose: {
backgroundColor: '#2196F3',
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
// [Windows
widthHeight: {
width: 300,
height: 400,
},
// Windows]
});

export default ({
title: "Modal's onShow/onDismiss",
name: 'onShow',
description:
'onShow and onDismiss (iOS only) callbacks are called when a modal is shown/dismissed',
render: (): React.Node => <ModalOnShowOnDismiss />,
}: RNTesterModuleExample);
Loading

0 comments on commit 15e5afb

Please sign in to comment.