Skip to content

Commit 1529ea5

Browse files
authored
[Fabric] Fix modal height (#14343)
* fix modal height * Change files * reverse change * add override
1 parent bb2851e commit 1529ea5

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "fix modal height",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/tester/overrides.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
"baseHash": "e840e1c091d2644d0a682b8baffad3b3dda2b207",
7676
"issue": 12869
7777
},
78+
{
79+
"type": "patch",
80+
"file": "src/js/examples/Modal/ModalOnShow.windows.js",
81+
"baseFile": "packages/rn-tester/js/examples/Modal/ModalOnShow.js",
82+
"baseHash": "911507abcf9172b5fdd1bb68faaf02562df704d4"
83+
},
7884
{
7985
"type": "patch",
8086
"file": "src/js/examples/Modal/ModalPresentation.windows.js",
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
12+
13+
import RNTesterText from '../../components/RNTesterText';
14+
import * as React from 'react';
15+
import {useState} from 'react';
16+
import {Modal, Pressable, StyleSheet, Text, View} from 'react-native';
17+
18+
function ModalOnShowOnDismiss(): React.Node {
19+
const [modalShowComponent, setModalShowComponent] = useState(true);
20+
const [modalVisible, setModalVisible] = useState(false);
21+
const [onShowCount, setOnShowCount] = useState(0);
22+
const [onDismissCount, setOnDismissCount] = useState(0);
23+
24+
return (
25+
<View style={styles.container}>
26+
{modalShowComponent && (
27+
<Modal
28+
animationType="slide"
29+
transparent={true}
30+
visible={modalVisible}
31+
onShow={() => {
32+
setOnShowCount(showCount => showCount + 1);
33+
}}
34+
onDismiss={() => {
35+
setOnDismissCount(dismissCount => dismissCount + 1);
36+
}}
37+
onRequestClose={() => {
38+
setModalVisible(false);
39+
}}>
40+
<View style={[styles.centeredView, styles.modalBackdrop]}>
41+
<View style={styles.modalView}>
42+
<Text testID="modal-on-show-count">
43+
onShow is called {onShowCount} times
44+
</Text>
45+
<Text testID="modal-on-dismiss-count">
46+
onDismiss is called {onDismissCount} times
47+
</Text>
48+
<Pressable
49+
style={[styles.button, styles.buttonClose]}
50+
onPress={() => setModalVisible(false)}>
51+
<Text testID="dismiss-modal" style={styles.textStyle}>
52+
Hide modal by setting visible to false
53+
</Text>
54+
</Pressable>
55+
<Pressable
56+
style={[styles.button, styles.buttonClose]}
57+
onPress={() => setModalShowComponent(false)}>
58+
<Text
59+
testID="dismiss-modal-by-removing-component"
60+
style={styles.textStyle}>
61+
Hide modal by removing component
62+
</Text>
63+
</Pressable>
64+
</View>
65+
</View>
66+
</Modal>
67+
)}
68+
<RNTesterText testID="on-show-count">
69+
onShow is called {onShowCount} times
70+
</RNTesterText>
71+
<RNTesterText testID="on-dismiss-count">
72+
onDismiss is called {onDismissCount} times
73+
</RNTesterText>
74+
<Pressable
75+
style={[styles.button, styles.buttonOpen]}
76+
onPress={() => {
77+
setModalShowComponent(true);
78+
setModalVisible(true);
79+
}}>
80+
<Text testID="open-modal" style={styles.textStyle}>
81+
Show Modal
82+
</Text>
83+
</Pressable>
84+
</View>
85+
);
86+
}
87+
88+
const styles = StyleSheet.create({
89+
container: {
90+
display: 'flex',
91+
alignItems: 'center',
92+
paddingVertical: 30,
93+
},
94+
centeredView: {
95+
// flex: 1, // [Windows] - This will cause the modal to stretch to be as tall as the availiable space given to it.
96+
justifyContent: 'center',
97+
alignItems: 'center',
98+
},
99+
modalBackdrop: {
100+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
101+
},
102+
modalView: {
103+
margin: 20,
104+
borderRadius: 20,
105+
padding: 35,
106+
alignItems: 'center',
107+
shadowColor: '#000',
108+
shadowOffset: {
109+
width: 0,
110+
height: 2,
111+
},
112+
shadowOpacity: 0.25,
113+
shadowRadius: 4,
114+
elevation: 5,
115+
},
116+
button: {
117+
borderRadius: 20,
118+
padding: 10,
119+
marginVertical: 20,
120+
elevation: 2,
121+
},
122+
buttonOpen: {
123+
backgroundColor: '#F194FF',
124+
},
125+
buttonClose: {
126+
backgroundColor: '#2196F3',
127+
},
128+
textStyle: {
129+
color: 'white',
130+
fontWeight: 'bold',
131+
textAlign: 'center',
132+
},
133+
});
134+
135+
export default ({
136+
title: "Modal's onShow/onDismiss",
137+
name: 'onShow',
138+
description:
139+
'onShow and onDismiss (iOS only) callbacks are called when a modal is shown/dismissed',
140+
render: (): React.Node => <ModalOnShowOnDismiss />,
141+
}: RNTesterModuleExample);

vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,13 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
167167
static_cast<int32_t>(layoutMetrics.Frame.Height * (layoutMetrics.PointScaleFactor))};
168168
m_popUp.MoveAndResize(rect2);
169169
#else
170+
// Fix for https://github.com/microsoft/microsoft-ui-xaml/issues/9529
171+
auto titleBarHeight = m_window.TitleBar().Height();
172+
170173
// Adjust window position and size
171174
m_window.ResizeClient(
172175
{static_cast<int32_t>(layoutMetrics.Frame.Width * (layoutMetrics.PointScaleFactor)),
173-
static_cast<int32_t>(layoutMetrics.Frame.Height * (layoutMetrics.PointScaleFactor))});
176+
static_cast<int32_t>(layoutMetrics.Frame.Height * (layoutMetrics.PointScaleFactor)) - titleBarHeight});
174177
m_window.Move({xCor, yCor});
175178
#endif
176179
};

0 commit comments

Comments
 (0)