Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary dispatch to main thread #45344

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions packages/react-native/Libraries/LogBox/UI/LogBoxInspectorHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
* @format
*/

import type {ViewProps} from '../../Components/View/ViewPropTypes';
import type {LogLevel} from '../Data/LogBoxLog';

import SafeAreaView from '../../Components/SafeAreaView/SafeAreaView';
import StatusBar from '../../Components/StatusBar/StatusBar';
import View from '../../Components/View/View';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text';
Expand All @@ -27,30 +26,16 @@ type Props = $ReadOnly<{
level: LogLevel,
}>;

const LogBoxInspectorHeaderSafeArea: React.AbstractComponent<ViewProps> =
Platform.OS === 'android'
? function LogBoxInspectorHeaderSafeArea(props) {
// NOTE: Inline the import of `StatusBar` so that initializing this module
// does not require initializing a TurboModule (and main thread one, too).
const {currentHeight} = require('../../Components/StatusBar/StatusBar');
const style = StyleSheet.compose(
{paddingTop: currentHeight},
props.style,
);
return <View {...props} style={style} />;
}
: SafeAreaView;

export default function LogBoxInspectorHeader(props: Props): React.Node {
if (props.level === 'syntax') {
return (
<LogBoxInspectorHeaderSafeArea style={styles[props.level]}>
<View style={[styles.safeArea, styles[props.level]]}>
<View style={styles.header}>
<View style={styles.title}>
<Text style={styles.titleText}>Failed to compile</Text>
</View>
</View>
</LogBoxInspectorHeaderSafeArea>
</View>
);
}

Expand All @@ -62,7 +47,7 @@ export default function LogBoxInspectorHeader(props: Props): React.Node {
const titleText = `Log ${props.selectedIndex + 1} of ${props.total}`;

return (
<LogBoxInspectorHeaderSafeArea style={styles[props.level]}>
<View style={[styles.safeArea, styles[props.level]]}>
<View style={styles.header}>
<LogBoxInspectorHeaderButton
disabled={props.total <= 1}
Expand All @@ -80,7 +65,7 @@ export default function LogBoxInspectorHeader(props: Props): React.Node {
onPress={() => props.onSelectIndex(nextIndex)}
/>
</View>
</LogBoxInspectorHeaderSafeArea>
</View>
);
}

Expand Down Expand Up @@ -116,4 +101,7 @@ const styles = StyleSheet.create({
includeFontPadding: false,
lineHeight: 20,
},
safeArea: {
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 40,
},
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LogBoxInspectorHeader should render both buttons for two total 1`] = `
<RCTSafeAreaView
<View
style={
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
}
Array [
Object {
"paddingTop": 40,
},
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
},
]
}
>
<View
Expand Down Expand Up @@ -60,15 +65,20 @@ exports[`LogBoxInspectorHeader should render both buttons for two total 1`] = `
onPress={[Function]}
/>
</View>
</RCTSafeAreaView>
</View>
`;

exports[`LogBoxInspectorHeader should render no buttons for one total 1`] = `
<RCTSafeAreaView
<View
style={
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
}
Array [
Object {
"paddingTop": 40,
},
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
},
]
}
>
<View
Expand Down Expand Up @@ -123,15 +133,20 @@ exports[`LogBoxInspectorHeader should render no buttons for one total 1`] = `
onPress={[Function]}
/>
</View>
</RCTSafeAreaView>
</View>
`;

exports[`LogBoxInspectorHeader should render syntax error header 1`] = `
<RCTSafeAreaView
<View
style={
Object {
"backgroundColor": "rgba(243, 83, 105, 1)",
}
Array [
Object {
"paddingTop": 40,
},
Object {
"backgroundColor": "rgba(243, 83, 105, 1)",
},
]
}
>
<View
Expand Down Expand Up @@ -166,15 +181,20 @@ exports[`LogBoxInspectorHeader should render syntax error header 1`] = `
</Text>
</View>
</View>
</RCTSafeAreaView>
</View>
`;

exports[`LogBoxInspectorHeader should render two buttons for three or more total 1`] = `
<RCTSafeAreaView
<View
style={
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
}
Array [
Object {
"paddingTop": 40,
},
Object {
"backgroundColor": "rgba(250, 186, 48, 1)",
},
]
}
>
<View
Expand Down Expand Up @@ -229,5 +249,5 @@ exports[`LogBoxInspectorHeader should render two buttons for three or more total
onPress={[Function]}
/>
</View>
</RCTSafeAreaView>
</View>
`;
11 changes: 3 additions & 8 deletions packages/react-native/React/CoreModules/RCTStatusBarManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,10 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification

- (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)getConstants
{
__block facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants> constants;
RCTUnsafeExecuteOnMainQueueSync(^{
constants = facebook::react::typedConstants<JS::NativeStatusBarManagerIOS::Constants>({
.HEIGHT = RCTUIStatusBarManager().statusBarFrame.size.height,
.DEFAULT_BACKGROUND_COLOR = std::nullopt,
});
return facebook::react::typedConstants<JS::NativeStatusBarManagerIOS::Constants>({
.HEIGHT = RCTUIStatusBarManager().statusBarFrame.size.height,
.DEFAULT_BACKGROUND_COLOR = std::nullopt,
});

return constants;
}

- (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)constantsToExport
Expand Down
Loading