Skip to content
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
6 changes: 4 additions & 2 deletions .storybook/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { createAsyncStorage } from '@react-native-async-storage/async-storage'

import { view } from './storybook.requires'

const storage = createAsyncStorage('storybook')

const StorybookUIRoot = view.getStorybookUI({
storage: { getItem: AsyncStorage.getItem, setItem: AsyncStorage.setItem },
storage,
theme: {
typography: {
size: {
Expand Down
60 changes: 51 additions & 9 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import type { Preview } from '@storybook/react'
import { StyleSheet } from 'react-native-unistyles'
import { ThemeContextProvider, ThemeVariant } from '../src'
import { View } from 'react-native'
import React, { type FunctionComponent, type ReactNode } from 'react'
import { useArgs } from '@storybook/preview-api'
import { StyleSheet, UnistylesRuntime } from 'react-native-unistyles'
import { ThemeContextProvider, ThemeVariant } from '../src/theme'
import { View, Appearance } from 'react-native'
import React, {
useEffect,
useLayoutEffect,
useRef,
type FunctionComponent,
type ReactNode,
} from 'react'

let currentTheme =
Appearance.getColorScheme() === 'dark'
? ThemeVariant.Dark
: ThemeVariant.Light

const preview: Preview = {
decorators: [
(Story, { args }) => {
(Story, context) => {
const [args, updateArgs] = useArgs<StorybookThemeArgs>()

return (
<Container theme={args.theme}>
<Container theme={args.theme} updateArgs={updateArgs}>
<View style={{ padding: 16, flex: 1 }}>
<Story />
</View>
Expand All @@ -26,17 +40,45 @@ const preview: Preview = {
control: { type: 'radio' },
},
},
args: { theme: ThemeVariant.Light },
args: { theme: currentTheme },
}

export default preview

interface StorybookThemeArgs {
theme: ThemeVariant
}

const THEME_NAME_MAP: Record<ThemeVariant, 'light' | 'dark'> = {
[ThemeVariant.Light]: 'light',
[ThemeVariant.Dark]: 'dark',
}

const Container: FunctionComponent<{
children: ReactNode
theme: ThemeVariant
}> = ({ children, theme }) => {
updateArgs: (args: StorybookThemeArgs) => void
}> = ({ children, theme, updateArgs }) => {
const themeSynchronized = useRef(false)

useEffect(() => {
if (!themeSynchronized.current) {
themeSynchronized.current = true
updateArgs({ theme: currentTheme })
}
}, [updateArgs])

useLayoutEffect(() => {
if (themeSynchronized.current) {
const nextTheme = THEME_NAME_MAP[theme]
Appearance.setColorScheme(nextTheme)
UnistylesRuntime.setTheme(nextTheme)
currentTheme = theme
}
}, [theme])

return (
<ThemeContextProvider initialTheme={theme}>
<ThemeContextProvider initialTheme={currentTheme}>
<View style={styles.container}>{children}</View>
</ThemeContextProvider>
)
Expand Down
20 changes: 12 additions & 8 deletions .storybook/storybook.requires.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* do not change this file, it is auto generated by storybook. */
import { start, updateView, View } from '@storybook/react-native';
/// <reference types="@storybook/react-native/metro-env" />
import { start, updateView, View, type Features } from '@storybook/react-native';

import "@storybook/addon-ondevice-notes/register";
import "@storybook/addon-ondevice-controls/register";
Expand All @@ -11,7 +12,6 @@ const normalizedStories = [
directory: "./src",
files: "**/*.stories.?(ts|tsx|js|jsx)",
importPathMatcher: /^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/,
// @ts-ignore
req: require.context(
'../src',
true,
Expand All @@ -24,6 +24,10 @@ const normalizedStories = [
declare global {
var view: View;
var STORIES: typeof normalizedStories;
var STORYBOOK_WEBSOCKET:
| { host?: string; port?: number; secured?: boolean }
| undefined;
var FEATURES: Features;
}


Expand All @@ -32,21 +36,21 @@ const annotations = [
require("@storybook/react-native/preview")
];

global.STORIES = normalizedStories;
globalThis.STORIES = normalizedStories;


// @ts-ignore
module?.hot?.accept?.();



if (!global.view) {
global.view = start({
if (!globalThis.view) {
globalThis.view = start({
annotations,
storyEntries: normalizedStories,

});
} else {
updateView(global.view, annotations, normalizedStories);
updateView(globalThis.view, annotations, normalizedStories);
}

export const view: View = global.view;
export const view: View = globalThis.view;
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
react {
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
hermesCommand = new File(["node", "--print", "require.resolve('hermes-compiler/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/hermesc/%OS-BIN%/hermesc"
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()

enableBundleCompression = (findProperty('android.enableBundleCompression') ?: false).toBoolean()
Expand Down
7 changes: 7 additions & 0 deletions android/app/src/debugOptimized/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:usesCleartextTraffic" />
</manifest>
8 changes: 4 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW"/>
Expand All @@ -15,7 +15,7 @@
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
33 changes: 11 additions & 22 deletions android/app/src/main/java/ru/cdek/uikit/prime/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,26 @@ import android.content.res.Configuration
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.ReactHost
import com.facebook.react.common.ReleaseLevel
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint
import com.facebook.react.defaults.DefaultReactNativeHost

import expo.modules.ApplicationLifecycleDispatcher
import expo.modules.ReactNativeHostWrapper
import expo.modules.ExpoReactHostFactory

class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper(
this,
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}

override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"

override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
}
)

override val reactHost: ReactHost
get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)
override val reactHost: ReactHost by lazy {
ExpoReactHostFactory.getDefaultReactHost(
context = applicationContext,
packageList =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}
)
}

override fun onCreate() {
super.onCreate()
Expand Down
1 change: 0 additions & 1 deletion android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
<color name="splashscreen_background">#FFFFFF</color>
<color name="iconBackground">#ffffff</color>
<color name="colorPrimary">#023c69</color>
<color name="colorPrimaryDark">#FFFFFF</color>
</resources>
1 change: 0 additions & 1 deletion android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<resources>
<string name="app_name">CDEK UI</string>
<string name="expo_splash_screen_resize_mode" translatable="false">cover</string>
<string name="expo_splash_screen_status_bar_translucent" translatable="false">false</string>
</resources>
4 changes: 2 additions & 2 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:enforceNavigationBarContrast" tools:targetApi="29">true</item>
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="android:statusBarColor">#FFFFFF</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
<item name="android:windowBackground">@drawable/ic_launcher_background</item>
Expand Down
4 changes: 0 additions & 4 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ EX_DEV_CLIENT_NETWORK_INSPECTOR=true

# Use legacy packaging to compress native libraries in the resulting APK.
expo.useLegacyPackaging=false

# Specifies whether the app is configured to use edge-to-edge via the app config or plugin
# WARNING: This property has been deprecated and will be removed in Expo SDK 55. Use `edgeToEdgeEnabled` or `react.edgeToEdgeEnabled` to determine whether the project is using edge-to-edge.
expo.edgeToEdgeEnabled=true
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion android/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default {
icon: './icon.png',
updates: { fallbackToCacheTimeout: 0 },
plugins: ['./expo/plugins/withEnsureBundler.js'],
newArchEnabled: true,
assetBundlePatterns: ['**/*'],
} satisfies ExpoConfig,
}
Loading
Loading