Skip to content

Commit 4449c1d

Browse files
authored
fix: iPad landscape mode broke the height reactions list (#2226)
* fix: iPad landscape mode broke the height reactions list * chore: enable ipad support
1 parent 0e84191 commit 4449c1d

File tree

2 files changed

+56
-27
lines changed

2 files changed

+56
-27
lines changed

examples/TypeScriptMessaging/ios/TypeScriptMessaging.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,12 @@
500500
);
501501
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
502502
PRODUCT_NAME = TypeScriptMessaging;
503+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
504+
SUPPORTS_MACCATALYST = NO;
505+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
503506
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
504507
SWIFT_VERSION = 5.0;
508+
TARGETED_DEVICE_FAMILY = "1,2";
505509
VERSIONING_SYSTEM = "apple-generic";
506510
};
507511
name = Debug;
@@ -526,7 +530,11 @@
526530
);
527531
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
528532
PRODUCT_NAME = TypeScriptMessaging;
533+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
534+
SUPPORTS_MACCATALYST = NO;
535+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
529536
SWIFT_VERSION = 5.0;
537+
TARGETED_DEVICE_FAMILY = "1,2";
530538
VERSIONING_SYSTEM = "apple-generic";
531539
};
532540
name = Release;

package/src/components/MessageOverlay/OverlayReactions.tsx

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const styles = StyleSheet.create({
6969
fontWeight: '700',
7070
paddingTop: 16,
7171
},
72+
unseenItemContainer: {
73+
opacity: 0,
74+
position: 'absolute',
75+
},
7276
});
7377

7478
const reactionData: ReactionData[] = [
@@ -138,6 +142,8 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
138142
const layoutHeight = useSharedValue(0);
139143
const layoutWidth = useSharedValue(0);
140144

145+
const [itemHeight, setItemHeight] = React.useState(0);
146+
141147
const {
142148
theme: {
143149
colors: { accent_blue, black, grey_gainsboro, white },
@@ -159,7 +165,6 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
159165
} = useTheme();
160166

161167
const width = useWindowDimensions().width;
162-
const height = useWindowDimensions().height;
163168

164169
const supportedReactionTypes = supportedReactions.map(
165170
(supportedReaction) => supportedReaction.type,
@@ -179,15 +184,6 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
179184
(avatarSize + (Number(avatarContainer.padding || 0) || styles.avatarContainer.padding) * 2),
180185
);
181186

182-
const maxHeight = Math.floor(
183-
height -
184-
overlayPadding * 2 -
185-
((Number(flatListContainer.paddingVertical || 0) ||
186-
styles.flatListContainer.paddingVertical) +
187-
(Number(avatarContainer.padding || 0) || styles.avatarContainer.padding)) *
188-
2,
189-
);
190-
191187
const renderItem = ({ item }: { item: Reaction }) => {
192188
const { alignment = 'left', name, type } = item;
193189
const x = avatarSize / 2 - (avatarSize / (radius * 4)) * (alignment === 'left' ? 1 : -1);
@@ -305,23 +301,48 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
305301
);
306302

307303
return (
308-
<Animated.View
309-
onLayout={({ nativeEvent: { layout } }) => {
310-
layoutWidth.value = layout.width;
311-
layoutHeight.value = layout.height;
312-
}}
313-
style={[styles.container, { backgroundColor: white }, container, showScreenStyle]}
314-
>
315-
<Text style={[styles.title, { color: black }, titleStyle]}>{title}</Text>
316-
<FlatList
317-
contentContainerStyle={styles.flatListContentContainer}
318-
data={filteredReactions}
319-
keyExtractor={({ name }, index) => `${name}_${index}`}
320-
numColumns={numColumns}
321-
renderItem={renderItem}
322-
style={[styles.flatListContainer, flatListContainer, { maxHeight: maxHeight / numColumns }]}
323-
/>
324-
</Animated.View>
304+
<>
305+
<Animated.View
306+
onLayout={({ nativeEvent: { layout } }) => {
307+
layoutWidth.value = layout.width;
308+
layoutHeight.value = layout.height;
309+
}}
310+
style={[
311+
styles.container,
312+
{ backgroundColor: white, opacity: itemHeight ? 1 : 0 },
313+
container,
314+
showScreenStyle,
315+
]}
316+
>
317+
<Text style={[styles.title, { color: black }, titleStyle]}>{title}</Text>
318+
<FlatList
319+
contentContainerStyle={styles.flatListContentContainer}
320+
data={filteredReactions}
321+
key={numColumns}
322+
keyExtractor={({ name }, index) => `${name}_${index}`}
323+
numColumns={numColumns}
324+
renderItem={renderItem}
325+
style={[
326+
styles.flatListContainer,
327+
flatListContainer,
328+
{
329+
// we show the item height plus a little extra to tease for scrolling if there are more than one row
330+
maxHeight:
331+
itemHeight + (filteredReactions.length / numColumns > 1 ? itemHeight / 8 : 0),
332+
},
333+
]}
334+
/>
335+
{/* The below view is unseen by the user, we use it to compute the height that the item must be */}
336+
<View
337+
onLayout={({ nativeEvent: { layout } }) => {
338+
setItemHeight(layout.height);
339+
}}
340+
style={[styles.unseenItemContainer, styles.flatListContentContainer]}
341+
>
342+
{renderItem({ item: filteredReactions[0] })}
343+
</View>
344+
</Animated.View>
345+
</>
325346
);
326347
};
327348

0 commit comments

Comments
 (0)