Tabii ki! Mevcut Arapça fontlarınıza bold (kalın) versiyonlarını eklemek için birkaç adım izlemeniz gerekiyor. Bu, fontların bold versiyonlarını yüklemek ve uygulamanızda kullanıma hazır hale getirmek anlamına gelir. Aşağıda, mevcut ThemeAndLanguageContext.js dosyanızda yapmanız gereken değişiklikleri adım adım açıklayacağım:
1. Bold Font Dosyalarını Projeye Ekleyin
İlk olarak, bold versiyonlarını kullanmak istediğiniz her font için .ttf dosyalarını projeye eklemeniz gerekiyor. Örneğin:
Scheherazade-Bold.ttf
Amiri-Bold.ttf
AdobeArabic-Bold.ttf
NotoNaskhArabic-Bold.ttf
Bu dosyaları, mevcut font dosyalarınızın bulunduğu klasöre (örneğin, assets/fonts/) ekleyin.
2. Font Yüklemelerini Güncelleyin
loadFonts fonksiyonunu, bold versiyonlu fontları da yükleyecek şekilde güncelleyin:
const loadFonts = async () => {
await Font.loadAsync({
// Mevcut Arapça fontlarınız
'Adobe Arabic': require('../../assets/fonts/adobearabic.ttf'),
'Adobe Arabic-Bold': require('../../assets/fonts/adobearabic-Bold.ttf'), // Bold versiyon
'Scheherazade': require('../../assets/fonts/scheherazade.ttf'),
'Scheherazade-Bold': require('../../assets/fonts/scheherazade-Bold.ttf'), // Bold versiyon
'Amiri': require('../../assets/fonts/amiri.ttf'),
'Amiri-Bold': require('../../assets/fonts/amiri-Bold.ttf'), // Bold versiyon
'Noto Naskh Arabic': require('../../assets/fonts/noto.ttf'),
'Noto Naskh Arabic-Bold': require('../../assets/fonts/noto-Bold.ttf'), // Bold versiyon
// Poppins fontları
'Poppins-Regular': require('../../assets/fonts/Poppins-Regular.ttf'),
'Poppins-Bold': require('../../assets/fonts/Poppins-Bold.ttf'),
'Poppins-Italic': require('../../assets/fonts/Poppins-Italic.ttf'),
// Diğer Poppins stillerini ekleyin
});
setFontsLoaded(true);
};
3. Context Değerlerini Güncelleyin
Bold fontları kullanıma sunmak için context'e ekleyebilirsiniz. Örneğin, her fontun regular ve bold versiyonlarını ayrı ayrı tanımlayabilirsiniz:
const contextValue = {
theme,
themeType,
locale,
setThemeType: changeTheme, // Temayı güncelleme fonksiyonu
changeLanguage,
t: (key, options) => i18n.t(key, options),
// Arapça fontlar
arabicFontRegular: fontFamily, // Varsayılan Arapça regular font
arabicFontBold: `${fontFamily}-Bold`, // Arapça bold font
setFontFamily: updateFontFamily, // Font güncelleme işlevi
// Poppins fontları
poppinsRegular: 'Poppins-Regular', // Poppins Regular
poppinsBold: 'Poppins-Bold', // Poppins Bold
poppinsItalic: 'Poppins-Italic', // Poppins Italic
// Diğer Poppins stillerini ekleyebilirsiniz
};
4. Font Kullanımını Ayarlayın
Artık uygulamanızda bold fontları kullanmak için context'ten erişebilirsiniz. Örneğin:
import React from 'react';
import { Text } from 'react-native';
import { useThemeAndLanguage } from '../utils/ThemeAndLanguageContext';
const SampleText = () => {
const { arabicFontRegular, arabicFontBold, t } = useThemeAndLanguage();
return (
<>
<Text style={{ fontFamily: arabicFontRegular, fontSize: 16 }}>
{t('regularTextKey')}
</Text>
<Text style={{ fontFamily: arabicFontBold, fontSize: 16 }}>
{t('boldTextKey')}
</Text>
</>
);
};
export default SampleText;
5. Gerekli Değişiklikleri Yapın
Eğer belirli bileşenlerde font ağırlığını dinamik olarak değiştirmek isterseniz, ek Prop'lar veya context üzerinden ekstra fonksiyonlar tanımlayarak daha esnek bir yapı oluşturabilirsiniz. Ancak, yukarıdaki adımlar temel olarak bold fontları eklemenizi ve kullanmanızı sağlayacaktır.
Güncellenmiş ThemeAndLanguageContext.js Dosyası
Aşağıda, tüm önerilen değişiklikleri içeren güncellenmiş tam dosya örneğini bulabilirsiniz:
// src/utils/ThemeAndLanguageContext.js
import React, { createContext, useContext, useState, useEffect } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Localization from 'expo-localization';
import { I18n } from 'i18n-js';
import { Appearance } from 'react-native';
import * as Font from 'expo-font';
import { setStatusBarStyle } from 'expo-status-bar';
import { darkTheme } from '../themes/darkTheme';
import { lightTheme } from '../themes/lightTheme';
import { vibrantTheme } from '../themes/vibrantTheme';
import { secretGardenTheme } from '../themes/secretGardenTheme';
import { slateDarkTheme } from '../themes/slateDarkTheme';
import { blackOrangeTheme } from '../themes/blackOrangeTheme';
const i18n = new I18n({
en: require('../locales/en.json'),
tr: require('../locales/tr.json'),
// Diğer dilleri buraya ekleyin
});
i18n.enableFallback = true;
const ThemeAndLanguageContext = createContext();
export const ThemeAndLanguageProvider = ({ children }) => {
const [themeType, setThemeType] = useState('light');
const [locale, setLocale] = useState(Localization.locale);
const [isLoading, setIsLoading] = useState(true);
const [fontsLoaded, setFontsLoaded] = useState(false);
const [fontFamily, setFontFamily] = useState('Scheherazade'); // Varsayılan Arapça font
useEffect(() => {
const loadSettings = async () => {
try {
const storedTheme = await AsyncStorage.getItem('theme');
const storedLocale = await AsyncStorage.getItem('locale');
const storedFontFamily = await AsyncStorage.getItem('fontFamily');
if (storedTheme) {
setThemeType(storedTheme);
} else {
const defaultTheme = Appearance.getColorScheme();
setThemeType(defaultTheme || 'light');
}
if (storedLocale) {
setLocale(storedLocale);
i18n.locale = storedLocale;
} else {
const defaultLocale = Localization.locale.startsWith('tr') ? 'tr' : 'en';
i18n.locale = defaultLocale;
setLocale(defaultLocale);
}
if (storedFontFamily) {
setFontFamily(storedFontFamily);
}
} catch (error) {
console.error('Error loading settings:', error);
} finally {
setIsLoading(false);
}
};
const loadFonts = async () => {
await Font.loadAsync({
// Mevcut Arapça fontlarınız
'Adobe Arabic': require('../../assets/fonts/adobearabic.ttf'),
'Adobe Arabic-Bold': require('../../assets/fonts/adobearabic-Bold.ttf'), // Bold versiyon
'Scheherazade': require('../../assets/fonts/scheherazade.ttf'),
'Scheherazade-Bold': require('../../assets/fonts/scheherazade-Bold.ttf'), // Bold versiyon
'Amiri': require('../../assets/fonts/amiri.ttf'),
'Amiri-Bold': require('../../assets/fonts/amiri-Bold.ttf'), // Bold versiyon
'Noto Naskh Arabic': require('../../assets/fonts/noto.ttf'),
'Noto Naskh Arabic-Bold': require('../../assets/fonts/noto-Bold.ttf'), // Bold versiyon
// Poppins fontları
'Poppins-Regular': require('../../assets/fonts/Poppins-Regular.ttf'),
'Poppins-Bold': require('../../assets/fonts/Poppins-Bold.ttf'),
'Poppins-Italic': require('../../assets/fonts/Poppins-Italic.ttf'),
// Diğer Poppins stillerini ekleyin
});
setFontsLoaded(true);
};
loadSettings();
loadFonts();
}, []);
useEffect(() => {
setStatusBarStyle(
themeType === 'dark' ||
themeType === 'blackOrange' ||
themeType === 'slateDark' ||
themeType === 'secretGarden' ||
themeType === 'vibrant'
? 'light'
: 'dark'
);
}, [themeType]);
const theme =
themeType === 'vibrant'
? vibrantTheme
: themeType === 'secretGarden'
? secretGardenTheme
: themeType === 'slateDark'
? slateDarkTheme
: themeType === 'blackOrange'
? blackOrangeTheme
: themeType === 'dark'
? darkTheme
: lightTheme;
const changeTheme = async (newThemeType) => {
setThemeType(newThemeType);
await AsyncStorage.setItem('theme', newThemeType);
};
const changeLanguage = async (newLocale) => {
setLocale(newLocale);
i18n.locale = newLocale;
await AsyncStorage.setItem('locale', newLocale);
};
const updateFontFamily = async (newFontFamily) => {
setFontFamily(newFontFamily);
await AsyncStorage.setItem('fontFamily', newFontFamily);
};
if (isLoading || !fontsLoaded) {
return null; // Yükleniyor durumunda hiçbir şey render edilmez
}
const contextValue = {
theme,
themeType,
locale,
setThemeType: changeTheme, // Temayı güncelleme fonksiyonu
changeLanguage,
t: (key, options) => i18n.t(key, options),
// Arapça fontlar
arabicFontRegular: fontFamily, // Varsayılan Arapça regular font
arabicFontBold: `${fontFamily}-Bold`, // Arapça bold font
setFontFamily: updateFontFamily, // Font güncelleme işlevi
// Poppins fontları
poppinsRegular: 'Poppins-Regular', // Poppins Regular
poppinsBold: 'Poppins-Bold', // Poppins Bold
poppinsItalic: 'Poppins-Italic', // Poppins Italic
// Diğer Poppins stillerini ekleyebilirsiniz
};
return (
<ThemeAndLanguageContext.Provider value={contextValue}>
{children}
</ThemeAndLanguageContext.Provider>
);
};
export const useThemeAndLanguage = () => {
const context = useContext(ThemeAndLanguageContext);
if (context === undefined) {
throw new Error('useThemeAndLanguage must be used within a ThemeAndLanguageProvider');
}
return context;
};
6. Kullanım Örneği
Artık uygulamanızda bold Arapça fontları kullanabilirsiniz. Aşağıda bir örnek kullanım görebilirsiniz:
import React from 'react';
import { Text, View } from 'react-native';
import { useThemeAndLanguage } from '../utils/ThemeAndLanguageContext';
const ArabicTextExample = () => {
const { arabicFontRegular, arabicFontBold, t } = useThemeAndLanguage();
return (
<View>
<Text style={{ fontFamily: arabicFontRegular, fontSize: 18 }}>
{t('regularArabicTextKey')}
</Text>
<Text style={{ fontFamily: arabicFontBold, fontSize: 18 }}>
{t('boldArabicTextKey')}
</Text>
</View>
);
};
export default ArabicTextExample;
Bu örnekte, regularArabicTextKey ve boldArabicTextKey i18n dosyanızda tanımlı olan metin anahtarlarıdır. Bu şekilde, hem regular hem de bold fontları kolayca kullanabilirsiniz.
7. Notlar ve İpuçları
-
Dinamik Font Ağırlığı: Eğer uygulamanızda dinamik olarak fontWeight kullanmak istiyorsanız, custom fontlarda bu genellikle çalışmaz. Bunun yerine, fontFamily'i doğru versiyonla (regular, bold vb.) değiştirmek gerekir.
-
Font Değişiklikleri: Font ailesini değiştirdiğinizde, tüm metin bileşenlerinizin doğru font ailesini kullanmasını sağlamak için bileşenlerinizde fontFamily atamalarını kontrol edin.
-
Performans: Font dosyalarını çok fazla yüklemek uygulamanızın performansını etkileyebilir. Gereksiz font dosyalarını yüklemediğinizden emin olun.
Bu adımları takip ederek Arapça fontlarınızın bold versiyonlarını başarıyla ekleyebilir ve uygulamanızda kullanabilirsiniz. Herhangi bir sorunla karşılaşırsanız veya ek yardım gerekirse lütfen bana bildirin!