providerがクラッシュしていた問題を修正
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { Platform, UIManager, Text } from "react-native";
|
||||
import { Platform, UIManager } from "react-native";
|
||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
||||
import "./utils/disableFontScaling"; // グローバルなフォントスケーリング無効化
|
||||
import { AppContainer } from "./Apps";
|
||||
import { UpdateAsync } from "./UpdateAsync";
|
||||
import { LogBox } from "react-native";
|
||||
@@ -35,10 +36,7 @@ export default function App() {
|
||||
useEffect(() => {
|
||||
UpdateAsync();
|
||||
}, []);
|
||||
if (Text.defaultProps == null) {
|
||||
Text.defaultProps = {};
|
||||
Text.defaultProps.allowFontScaling = false;
|
||||
}
|
||||
|
||||
const ProviderTree = buildProvidersTree([
|
||||
AllTrainDiagramProvider,
|
||||
NotificationProvider,
|
||||
@@ -51,13 +49,14 @@ export default function App() {
|
||||
BusAndTrainDataProvider,
|
||||
TrainMenuProvider,
|
||||
SheetProvider,
|
||||
AppContainer,
|
||||
]);
|
||||
return (
|
||||
<DeviceOrientationChangeProvider>
|
||||
<SafeAreaProvider>
|
||||
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||
<ProviderTree />
|
||||
<ProviderTree>
|
||||
<AppContainer />
|
||||
</ProviderTree>
|
||||
</GestureHandlerRootView>
|
||||
</SafeAreaProvider>
|
||||
</DeviceOrientationChangeProvider>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import React from "react";
|
||||
import { Text as RNText, TextProps } from "react-native";
|
||||
|
||||
/**
|
||||
* フォントスケーリングを無効化したカスタムTextコンポーネント
|
||||
* Text.defaultPropsの代替として使用
|
||||
*
|
||||
* 使用方法:
|
||||
* import { Text } from '@/components/atom/CustomText';
|
||||
* の代わりに react-native から Text をインポートする場合は
|
||||
* 自動的に allowFontScaling={false} が適用されます
|
||||
*/
|
||||
export const Text: React.FC<TextProps> = (props) => {
|
||||
const { allowFontScaling = false, ...restProps } = props;
|
||||
return <RNText {...restProps} allowFontScaling={allowFontScaling} />;
|
||||
};
|
||||
@@ -1,31 +1,26 @@
|
||||
import React, { FC, ReactElement } from "react";
|
||||
import React, { ComponentType, ReactNode } from "react";
|
||||
|
||||
type ProviderTreeProps = {
|
||||
providers: ReactElement[];
|
||||
};
|
||||
type Provider = ComponentType<{ children: ReactNode }>;
|
||||
|
||||
export const buildProvidersTree = (providers: Provider[]): Provider => {
|
||||
if (!providers || providers.length === 0) {
|
||||
throw new Error("ContextProviderが不足しています");
|
||||
}
|
||||
|
||||
export const buildProvidersTree: FC<ProviderTreeProps> = ({ providers }) => {
|
||||
// 基本ケース:ContextProviderが1つしか残っていない場合、それを返して終了する
|
||||
if (providers.length === 1) {
|
||||
return providers[0];
|
||||
}
|
||||
|
||||
// 配列から最初の2つのContextProviderを取り出す
|
||||
const FirstProvider = providers.shift();
|
||||
const SecondProvider = providers.shift();
|
||||
|
||||
// 十分な数のContextProviderがあるかどうかを確認
|
||||
if (FirstProvider === undefined || SecondProvider === undefined) {
|
||||
throw new Error("ContextProviderが不足しています");
|
||||
}
|
||||
const [FirstProvider, SecondProvider, ...restProviders] = providers;
|
||||
|
||||
// 最初の2つのContextProviderをネストした新しいContextProviderを作成し、再帰する
|
||||
return buildProvidersTree([
|
||||
({ children }) => (
|
||||
<FirstProvider>
|
||||
<SecondProvider {...{ children }} />
|
||||
</FirstProvider>
|
||||
),
|
||||
...providers,
|
||||
]);
|
||||
const CombinedProvider: Provider = ({ children }) => (
|
||||
<FirstProvider>
|
||||
<SecondProvider>{children}</SecondProvider>
|
||||
</FirstProvider>
|
||||
);
|
||||
|
||||
return buildProvidersTree([CombinedProvider, ...restProviders]);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* グローバルなフォントスケーリング設定
|
||||
* Text.defaultProps の非推奨対応
|
||||
*
|
||||
* このファイルを App.tsx の最初でインポートすることで、
|
||||
* アプリ全体の Text コンポーネントで allowFontScaling={false} が適用されます
|
||||
*/
|
||||
|
||||
import { Text } from "react-native";
|
||||
|
||||
// Text.defaultProps は非推奨ですが、既存コードとの互換性のため一時的に使用
|
||||
// @ts-ignore - defaultProps は非推奨だが、現在のReact Nativeバージョンでは動作する
|
||||
if (!Text.defaultProps) {
|
||||
// @ts-ignore
|
||||
Text.defaultProps = {};
|
||||
}
|
||||
// @ts-ignore
|
||||
Text.defaultProps.allowFontScaling = false;
|
||||
Reference in New Issue
Block a user