@robin-ux/native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -0
- package/README.md +35 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/robinuxnative/RobinUxNativeModule.kt +50 -0
- package/android/src/main/java/expo/modules/robinuxnative/RobinUxNativeView.kt +30 -0
- package/build/RobinUxNative.types.d.ts +18 -0
- package/build/RobinUxNative.types.d.ts.map +1 -0
- package/build/RobinUxNative.types.js +2 -0
- package/build/RobinUxNative.types.js.map +1 -0
- package/build/RobinUxNativeModule.d.ts +10 -0
- package/build/RobinUxNativeModule.d.ts.map +1 -0
- package/build/RobinUxNativeModule.js +4 -0
- package/build/RobinUxNativeModule.js.map +1 -0
- package/build/RobinUxNativeModule.web.d.ts +10 -0
- package/build/RobinUxNativeModule.web.d.ts.map +1 -0
- package/build/RobinUxNativeModule.web.js +12 -0
- package/build/RobinUxNativeModule.web.js.map +1 -0
- package/build/RobinUxNativeView.d.ts +4 -0
- package/build/RobinUxNativeView.d.ts.map +1 -0
- package/build/RobinUxNativeView.js +7 -0
- package/build/RobinUxNativeView.js.map +1 -0
- package/build/RobinUxNativeView.web.d.ts +4 -0
- package/build/RobinUxNativeView.web.d.ts.map +1 -0
- package/build/RobinUxNativeView.web.js +7 -0
- package/build/RobinUxNativeView.web.js.map +1 -0
- package/build/components/Badge.d.ts +36 -0
- package/build/components/Badge.d.ts.map +1 -0
- package/build/components/Badge.js +78 -0
- package/build/components/Badge.js.map +1 -0
- package/build/components/Button.d.ts +43 -0
- package/build/components/Button.d.ts.map +1 -0
- package/build/components/Button.js +120 -0
- package/build/components/Button.js.map +1 -0
- package/build/components/DynamicStatusBar.d.ts +30 -0
- package/build/components/DynamicStatusBar.d.ts.map +1 -0
- package/build/components/DynamicStatusBar.js +70 -0
- package/build/components/DynamicStatusBar.js.map +1 -0
- package/build/components/Input.d.ts +73 -0
- package/build/components/Input.d.ts.map +1 -0
- package/build/components/Input.js +138 -0
- package/build/components/Input.js.map +1 -0
- package/build/components/SegmentedControl.d.ts +40 -0
- package/build/components/SegmentedControl.d.ts.map +1 -0
- package/build/components/SegmentedControl.js +73 -0
- package/build/components/SegmentedControl.js.map +1 -0
- package/build/components/Text.d.ts +32 -0
- package/build/components/Text.d.ts.map +1 -0
- package/build/components/Text.js +51 -0
- package/build/components/Text.js.map +1 -0
- package/build/components/index.d.ts +13 -0
- package/build/components/index.d.ts.map +1 -0
- package/build/components/index.js +13 -0
- package/build/components/index.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +10 -0
- package/build/index.js.map +1 -0
- package/build/theme/ThemeContext.d.ts +22 -0
- package/build/theme/ThemeContext.d.ts.map +1 -0
- package/build/theme/ThemeContext.js +35 -0
- package/build/theme/ThemeContext.js.map +1 -0
- package/build/theme/ThemeProvider.d.ts +33 -0
- package/build/theme/ThemeProvider.d.ts.map +1 -0
- package/build/theme/ThemeProvider.js +31 -0
- package/build/theme/ThemeProvider.js.map +1 -0
- package/build/theme/defaultTheme.d.ts +18 -0
- package/build/theme/defaultTheme.d.ts.map +1 -0
- package/build/theme/defaultTheme.js +77 -0
- package/build/theme/defaultTheme.js.map +1 -0
- package/build/theme/index.d.ts +6 -0
- package/build/theme/index.d.ts.map +1 -0
- package/build/theme/index.js +7 -0
- package/build/theme/index.js.map +1 -0
- package/build/theme/types.d.ts +40 -0
- package/build/theme/types.d.ts.map +1 -0
- package/build/theme/types.js +2 -0
- package/build/theme/types.js.map +1 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +3 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/styles.d.ts +88 -0
- package/build/utils/styles.d.ts.map +1 -0
- package/build/utils/styles.js +150 -0
- package/build/utils/styles.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/RobinUxNative.podspec +29 -0
- package/ios/RobinUxNativeModule.swift +48 -0
- package/ios/RobinUxNativeView.swift +38 -0
- package/package.json +69 -0
- package/src/RobinUxNative.types.ts +19 -0
- package/src/RobinUxNativeModule.ts +12 -0
- package/src/RobinUxNativeModule.web.ts +15 -0
- package/src/RobinUxNativeView.tsx +11 -0
- package/src/RobinUxNativeView.web.tsx +15 -0
- package/src/components/Badge.tsx +101 -0
- package/src/components/Button.tsx +176 -0
- package/src/components/DynamicStatusBar.tsx +93 -0
- package/src/components/Input.tsx +248 -0
- package/src/components/SegmentedControl.tsx +107 -0
- package/src/components/Text.tsx +107 -0
- package/src/components/index.ts +23 -0
- package/src/index.ts +70 -0
- package/src/theme/ThemeContext.ts +38 -0
- package/src/theme/ThemeProvider.tsx +45 -0
- package/src/theme/defaultTheme.ts +91 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/types.ts +52 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/styles.ts +188 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'RobinUxNative'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = {
|
|
14
|
+
:ios => '15.1',
|
|
15
|
+
:tvos => '15.1'
|
|
16
|
+
}
|
|
17
|
+
s.swift_version = '5.9'
|
|
18
|
+
s.source = { git: 'https://github.com/robinqc/robin-ux-native' }
|
|
19
|
+
s.static_framework = true
|
|
20
|
+
|
|
21
|
+
s.dependency 'ExpoModulesCore'
|
|
22
|
+
|
|
23
|
+
# Swift/Objective-C compatibility
|
|
24
|
+
s.pod_target_xcconfig = {
|
|
25
|
+
'DEFINES_MODULE' => 'YES',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
|
29
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
public class RobinUxNativeModule: Module {
|
|
4
|
+
// Each module class must implement the definition function. The definition consists of components
|
|
5
|
+
// that describes the module's functionality and behavior.
|
|
6
|
+
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
7
|
+
public func definition() -> ModuleDefinition {
|
|
8
|
+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
9
|
+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
10
|
+
// The module will be accessible from `requireNativeModule('RobinUxNative')` in JavaScript.
|
|
11
|
+
Name("RobinUxNative")
|
|
12
|
+
|
|
13
|
+
// Defines constant property on the module.
|
|
14
|
+
Constant("PI") {
|
|
15
|
+
Double.pi
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Defines event names that the module can send to JavaScript.
|
|
19
|
+
Events("onChange")
|
|
20
|
+
|
|
21
|
+
// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
|
|
22
|
+
Function("hello") {
|
|
23
|
+
return "Hello world! 👋"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
27
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
28
|
+
AsyncFunction("setValueAsync") { (value: String) in
|
|
29
|
+
// Send an event to JavaScript.
|
|
30
|
+
self.sendEvent("onChange", [
|
|
31
|
+
"value": value
|
|
32
|
+
])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Enables the module to be used as a native view. Definition components that are accepted as part of the
|
|
36
|
+
// view definition: Prop, Events.
|
|
37
|
+
View(RobinUxNativeView.self) {
|
|
38
|
+
// Defines a setter for the `url` prop.
|
|
39
|
+
Prop("url") { (view: RobinUxNativeView, url: URL) in
|
|
40
|
+
if view.webView.url != url {
|
|
41
|
+
view.webView.load(URLRequest(url: url))
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Events("onLoad")
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import WebKit
|
|
3
|
+
|
|
4
|
+
// This view will be used as a native component. Make sure to inherit from `ExpoView`
|
|
5
|
+
// to apply the proper styling (e.g. border radius and shadows).
|
|
6
|
+
class RobinUxNativeView: ExpoView {
|
|
7
|
+
let webView = WKWebView()
|
|
8
|
+
let onLoad = EventDispatcher()
|
|
9
|
+
var delegate: WebViewDelegate?
|
|
10
|
+
|
|
11
|
+
required init(appContext: AppContext? = nil) {
|
|
12
|
+
super.init(appContext: appContext)
|
|
13
|
+
clipsToBounds = true
|
|
14
|
+
delegate = WebViewDelegate { url in
|
|
15
|
+
self.onLoad(["url": url])
|
|
16
|
+
}
|
|
17
|
+
webView.navigationDelegate = delegate
|
|
18
|
+
addSubview(webView)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override func layoutSubviews() {
|
|
22
|
+
webView.frame = bounds
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class WebViewDelegate: NSObject, WKNavigationDelegate {
|
|
27
|
+
let onUrlChange: (String) -> Void
|
|
28
|
+
|
|
29
|
+
init(onUrlChange: @escaping (String) -> Void) {
|
|
30
|
+
self.onUrlChange = onUrlChange
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation) {
|
|
34
|
+
if let url = webView.url {
|
|
35
|
+
onUrlChange(url.absoluteString)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@robin-ux/native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Themeable React Native UI components for Expo projects",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"open:ios": "xed example/ios",
|
|
16
|
+
"open:android": "open -a \"Android Studio\" example/android"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"expo",
|
|
21
|
+
"ui-components",
|
|
22
|
+
"theme",
|
|
23
|
+
"button",
|
|
24
|
+
"input",
|
|
25
|
+
"text",
|
|
26
|
+
"badge",
|
|
27
|
+
"segmented-control",
|
|
28
|
+
"robin-ux"
|
|
29
|
+
],
|
|
30
|
+
"repository": "https://github.com/robinqc/-robin-ux-native",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/robinqc/-robin-ux-native/issues"
|
|
33
|
+
},
|
|
34
|
+
"author": "robinqc <robinquinteroc@gmail.com> (https://github.com/robinqc)",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"homepage": "https://github.com/robinqc/-robin-ux-native#readme",
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@expo/vector-icons": "^15.0.0",
|
|
40
|
+
"@types/react": "~19.1.0",
|
|
41
|
+
"expo": "^54.0.27",
|
|
42
|
+
"expo-module-scripts": "^5.0.8",
|
|
43
|
+
"expo-status-bar": "~3.0.0",
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"react-hook-form": "^7.50.0",
|
|
46
|
+
"react-native": "0.81.5",
|
|
47
|
+
"react-native-safe-area-context": "~5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@expo/vector-icons": "*",
|
|
51
|
+
"expo": "*",
|
|
52
|
+
"expo-status-bar": "*",
|
|
53
|
+
"react": "*",
|
|
54
|
+
"react-hook-form": ">=7.0.0",
|
|
55
|
+
"react-native": "*",
|
|
56
|
+
"react-native-safe-area-context": "*"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"react-hook-form": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"expo-status-bar": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"react-native-safe-area-context": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type OnLoadEventPayload = {
|
|
4
|
+
url: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type RobinUxNativeModuleEvents = {
|
|
8
|
+
onChange: (params: ChangeEventPayload) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ChangeEventPayload = {
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type RobinUxNativeViewProps = {
|
|
16
|
+
url: string;
|
|
17
|
+
onLoad: (event: { nativeEvent: OnLoadEventPayload }) => void;
|
|
18
|
+
style?: StyleProp<ViewStyle>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NativeModule, requireNativeModule } from 'expo';
|
|
2
|
+
|
|
3
|
+
import { RobinUxNativeModuleEvents } from './RobinUxNative.types';
|
|
4
|
+
|
|
5
|
+
declare class RobinUxNativeModule extends NativeModule<RobinUxNativeModuleEvents> {
|
|
6
|
+
PI: number;
|
|
7
|
+
hello(): string;
|
|
8
|
+
setValueAsync(value: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// This call loads the native module object from the JSI.
|
|
12
|
+
export default requireNativeModule<RobinUxNativeModule>('RobinUxNative');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { registerWebModule, NativeModule } from 'expo';
|
|
2
|
+
|
|
3
|
+
import { RobinUxNativeModuleEvents } from './RobinUxNative.types';
|
|
4
|
+
|
|
5
|
+
class RobinUxNativeModule extends NativeModule<RobinUxNativeModuleEvents> {
|
|
6
|
+
PI = Math.PI;
|
|
7
|
+
async setValueAsync(value: string): Promise<void> {
|
|
8
|
+
this.emit('onChange', { value });
|
|
9
|
+
}
|
|
10
|
+
hello() {
|
|
11
|
+
return 'Hello world! 👋';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default registerWebModule(RobinUxNativeModule, 'RobinUxNativeModule');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { requireNativeView } from 'expo';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { RobinUxNativeViewProps } from './RobinUxNative.types';
|
|
5
|
+
|
|
6
|
+
const NativeView: React.ComponentType<RobinUxNativeViewProps> =
|
|
7
|
+
requireNativeView('RobinUxNative');
|
|
8
|
+
|
|
9
|
+
export default function RobinUxNativeView(props: RobinUxNativeViewProps) {
|
|
10
|
+
return <NativeView {...props} />;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { RobinUxNativeViewProps } from './RobinUxNative.types';
|
|
4
|
+
|
|
5
|
+
export default function RobinUxNativeView(props: RobinUxNativeViewProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<iframe
|
|
9
|
+
style={{ flex: 1 }}
|
|
10
|
+
src={props.url}
|
|
11
|
+
onLoad={() => props.onLoad({ nativeEvent: { url: props.url } })}
|
|
12
|
+
/>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, View, ViewStyle } from 'react-native';
|
|
3
|
+
import { useThemeSafe } from '../theme';
|
|
4
|
+
import { borderRadius, spacing, useThemedStyles } from '../utils/styles';
|
|
5
|
+
import { Text } from './Text';
|
|
6
|
+
|
|
7
|
+
export type BadgeStatus = 'active' | 'archived' | 'draft' | string;
|
|
8
|
+
|
|
9
|
+
export interface BadgeProps {
|
|
10
|
+
/** Status or label to display */
|
|
11
|
+
status: BadgeStatus;
|
|
12
|
+
/** Badge size */
|
|
13
|
+
size?: 'sm' | 'md';
|
|
14
|
+
/** Custom container style */
|
|
15
|
+
style?: StyleProp<ViewStyle>;
|
|
16
|
+
/** Custom color override */
|
|
17
|
+
customColor?: {
|
|
18
|
+
background: string;
|
|
19
|
+
text: string;
|
|
20
|
+
border: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Badge component for displaying status or labels.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <Badge status="active" />
|
|
30
|
+
* <Badge status="draft" size="sm" />
|
|
31
|
+
* <Badge
|
|
32
|
+
* status="Custom"
|
|
33
|
+
* customColor={{
|
|
34
|
+
* background: '#e0f2fe',
|
|
35
|
+
* text: '#0369a1',
|
|
36
|
+
* border: '#7dd3fc',
|
|
37
|
+
* }}
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function Badge({ status, size = 'md', style, customColor }: BadgeProps) {
|
|
42
|
+
const { colors } = useThemeSafe();
|
|
43
|
+
|
|
44
|
+
// Default status colors
|
|
45
|
+
const getStatusColors = () => {
|
|
46
|
+
if (customColor) return customColor;
|
|
47
|
+
|
|
48
|
+
switch (status) {
|
|
49
|
+
case 'active':
|
|
50
|
+
return {
|
|
51
|
+
background: colors.success + '15', // 15% opacity
|
|
52
|
+
text: colors.success,
|
|
53
|
+
border: colors.success + '30', // 30% opacity
|
|
54
|
+
};
|
|
55
|
+
case 'archived':
|
|
56
|
+
return {
|
|
57
|
+
background: colors.foregroundTertiary + '15',
|
|
58
|
+
text: colors.foregroundTertiary,
|
|
59
|
+
border: colors.foregroundTertiary + '30',
|
|
60
|
+
};
|
|
61
|
+
case 'draft':
|
|
62
|
+
return {
|
|
63
|
+
background: colors.warning + '15',
|
|
64
|
+
text: colors.warning,
|
|
65
|
+
border: colors.warning + '30',
|
|
66
|
+
};
|
|
67
|
+
default:
|
|
68
|
+
return {
|
|
69
|
+
background: colors.muted,
|
|
70
|
+
text: colors.foregroundSecondary,
|
|
71
|
+
border: colors.border,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const statusColors = getStatusColors();
|
|
77
|
+
|
|
78
|
+
const styles = useThemedStyles(() => ({
|
|
79
|
+
badge: {
|
|
80
|
+
backgroundColor: statusColors.background,
|
|
81
|
+
borderWidth: 1,
|
|
82
|
+
borderColor: statusColors.border,
|
|
83
|
+
borderRadius: borderRadius.full,
|
|
84
|
+
paddingHorizontal: size === 'sm' ? spacing.sm : spacing.md,
|
|
85
|
+
paddingVertical: size === 'sm' ? spacing.xs : spacing.sm,
|
|
86
|
+
alignSelf: 'flex-start' as const,
|
|
87
|
+
},
|
|
88
|
+
text: {
|
|
89
|
+
color: statusColors.text,
|
|
90
|
+
fontSize: size === 'sm' ? 10 : 12,
|
|
91
|
+
fontWeight: '600' as const,
|
|
92
|
+
textTransform: 'capitalize' as const,
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<View style={[styles.badge, style]}>
|
|
98
|
+
<Text style={styles.text}>{status}</Text>
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ActivityIndicator, StyleSheet, TouchableOpacity, TouchableOpacityProps, View, ViewStyle } from "react-native";
|
|
4
|
+
import { useThemeSafe } from "../theme";
|
|
5
|
+
import { borderRadius, spacing } from "../utils/styles";
|
|
6
|
+
import { Text } from "./Text";
|
|
7
|
+
|
|
8
|
+
export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive";
|
|
9
|
+
export type ButtonSize = "sm" | "md" | "lg";
|
|
10
|
+
|
|
11
|
+
export interface ButtonProps extends Omit<TouchableOpacityProps, "style"> {
|
|
12
|
+
/** Button visual variant */
|
|
13
|
+
variant?: ButtonVariant;
|
|
14
|
+
/** Button size */
|
|
15
|
+
size?: ButtonSize;
|
|
16
|
+
/** Show loading spinner */
|
|
17
|
+
loading?: boolean;
|
|
18
|
+
/** Disable button interactions */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** Icon name from Ionicons */
|
|
21
|
+
icon?: keyof typeof Ionicons.glyphMap;
|
|
22
|
+
/** Icon position relative to children */
|
|
23
|
+
iconPosition?: "left" | "right";
|
|
24
|
+
/** Button content */
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
/** Custom style */
|
|
27
|
+
style?: TouchableOpacityProps["style"];
|
|
28
|
+
/** Ref to the button view */
|
|
29
|
+
ref?: React.RefObject<View | null>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface SizeConfig {
|
|
33
|
+
paddingVertical: number;
|
|
34
|
+
paddingHorizontal: number;
|
|
35
|
+
fontSize: number;
|
|
36
|
+
iconSize: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Button component with variants, sizes, and icon support.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <Button variant="primary" onPress={handlePress}>
|
|
45
|
+
* Submit
|
|
46
|
+
* </Button>
|
|
47
|
+
*
|
|
48
|
+
* <Button variant="secondary" icon="add" size="sm">
|
|
49
|
+
* Add Item
|
|
50
|
+
* </Button>
|
|
51
|
+
*
|
|
52
|
+
* <Button variant="ghost" icon="settings" />
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function Button({ variant = "primary", size = "md", loading = false, disabled = false, icon, iconPosition = "left", children, style, ref, ...props }: ButtonProps) {
|
|
56
|
+
const { colors } = useThemeSafe();
|
|
57
|
+
|
|
58
|
+
const isDisabled = disabled || loading;
|
|
59
|
+
|
|
60
|
+
// Size configurations
|
|
61
|
+
const sizeConfigs: Record<ButtonSize, SizeConfig> = {
|
|
62
|
+
sm: {
|
|
63
|
+
paddingVertical: spacing.sm,
|
|
64
|
+
paddingHorizontal: spacing.md,
|
|
65
|
+
fontSize: 14,
|
|
66
|
+
iconSize: 16,
|
|
67
|
+
},
|
|
68
|
+
md: {
|
|
69
|
+
paddingVertical: 14,
|
|
70
|
+
paddingHorizontal: spacing.lg,
|
|
71
|
+
fontSize: 16,
|
|
72
|
+
iconSize: 20,
|
|
73
|
+
},
|
|
74
|
+
lg: {
|
|
75
|
+
paddingVertical: 18,
|
|
76
|
+
paddingHorizontal: spacing.xl,
|
|
77
|
+
fontSize: 18,
|
|
78
|
+
iconSize: 24,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const sizeConfig = sizeConfigs[size];
|
|
83
|
+
|
|
84
|
+
// Variant styles
|
|
85
|
+
const variantStyles: Record<ButtonVariant, { backgroundColor: string; textColor: string }> = {
|
|
86
|
+
primary: {
|
|
87
|
+
backgroundColor: isDisabled ? colors.primaryLight : colors.primary,
|
|
88
|
+
textColor: colors.background,
|
|
89
|
+
},
|
|
90
|
+
secondary: {
|
|
91
|
+
backgroundColor: isDisabled ? colors.muted : colors.backgroundSecondary,
|
|
92
|
+
textColor: colors.foreground,
|
|
93
|
+
},
|
|
94
|
+
ghost: {
|
|
95
|
+
backgroundColor: "transparent",
|
|
96
|
+
textColor: colors.foreground,
|
|
97
|
+
},
|
|
98
|
+
destructive: {
|
|
99
|
+
backgroundColor: isDisabled ? colors.muted : colors.destructive,
|
|
100
|
+
textColor: colors.destructiveForeground,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const currentVariant = variantStyles[variant];
|
|
105
|
+
|
|
106
|
+
const buttonStyle: ViewStyle[] = [
|
|
107
|
+
styles.button,
|
|
108
|
+
{
|
|
109
|
+
backgroundColor: currentVariant.backgroundColor,
|
|
110
|
+
paddingVertical: sizeConfig.paddingVertical,
|
|
111
|
+
paddingHorizontal: sizeConfig.paddingHorizontal,
|
|
112
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
113
|
+
},
|
|
114
|
+
style as ViewStyle,
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
const renderContent = () => {
|
|
118
|
+
if (loading) {
|
|
119
|
+
return <ActivityIndicator size="small" color={currentVariant.textColor} />;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const iconElement = icon ? (
|
|
123
|
+
<Ionicons
|
|
124
|
+
name={icon}
|
|
125
|
+
size={sizeConfig.iconSize}
|
|
126
|
+
color={currentVariant.textColor}
|
|
127
|
+
style={children && iconPosition === "left" ? styles.iconLeft : children && iconPosition === "right" ? styles.iconRight : undefined}
|
|
128
|
+
/>
|
|
129
|
+
) : null;
|
|
130
|
+
|
|
131
|
+
if (!children) {
|
|
132
|
+
return iconElement;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<View style={styles.content}>
|
|
137
|
+
{iconPosition === "left" && iconElement}
|
|
138
|
+
<Text
|
|
139
|
+
style={{
|
|
140
|
+
color: currentVariant.textColor,
|
|
141
|
+
fontSize: sizeConfig.fontSize,
|
|
142
|
+
fontWeight: "600",
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{children}
|
|
146
|
+
</Text>
|
|
147
|
+
{iconPosition === "right" && iconElement}
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<TouchableOpacity style={buttonStyle} disabled={isDisabled} activeOpacity={0.7} ref={ref} {...props}>
|
|
154
|
+
{renderContent()}
|
|
155
|
+
</TouchableOpacity>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const styles = StyleSheet.create({
|
|
160
|
+
button: {
|
|
161
|
+
borderRadius: borderRadius.full,
|
|
162
|
+
alignItems: "center",
|
|
163
|
+
justifyContent: "center",
|
|
164
|
+
},
|
|
165
|
+
content: {
|
|
166
|
+
flexDirection: "row",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
justifyContent: "center",
|
|
169
|
+
},
|
|
170
|
+
iconLeft: {
|
|
171
|
+
marginRight: spacing.sm,
|
|
172
|
+
},
|
|
173
|
+
iconRight: {
|
|
174
|
+
marginLeft: spacing.sm,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { StatusBar } from 'expo-status-bar';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
+
import { useThemeSafe } from '../theme';
|
|
6
|
+
|
|
7
|
+
export interface DynamicStatusBarProps {
|
|
8
|
+
/** Animated scroll value to track */
|
|
9
|
+
scrollY: Animated.Value;
|
|
10
|
+
/** Scroll threshold for style change */
|
|
11
|
+
threshold?: number;
|
|
12
|
+
/** Default status bar style */
|
|
13
|
+
defaultStyle?: 'light' | 'dark';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dynamic status bar that changes style based on scroll position.
|
|
18
|
+
* Provides a smooth transition with animated background.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const scrollY = useRef(new Animated.Value(0)).current;
|
|
23
|
+
*
|
|
24
|
+
* <DynamicStatusBar scrollY={scrollY} threshold={200} />
|
|
25
|
+
* <Animated.ScrollView
|
|
26
|
+
* onScroll={Animated.event(
|
|
27
|
+
* [{ nativeEvent: { contentOffset: { y: scrollY } } }],
|
|
28
|
+
* { useNativeDriver: true }
|
|
29
|
+
* )}
|
|
30
|
+
* >
|
|
31
|
+
* {content}
|
|
32
|
+
* </Animated.ScrollView>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function DynamicStatusBar({
|
|
36
|
+
scrollY,
|
|
37
|
+
threshold = 200,
|
|
38
|
+
defaultStyle = 'light',
|
|
39
|
+
}: DynamicStatusBarProps) {
|
|
40
|
+
const { isDark, colors } = useThemeSafe();
|
|
41
|
+
const insets = useSafeAreaInsets();
|
|
42
|
+
const [style, setStyle] = useState<'light' | 'dark'>(defaultStyle);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const listener = scrollY.addListener(({ value }) => {
|
|
46
|
+
if (isDark) {
|
|
47
|
+
if (style !== 'light') setStyle('light');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const newStyle = value > threshold ? 'dark' : 'light';
|
|
52
|
+
if (newStyle !== style) {
|
|
53
|
+
setStyle(newStyle);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return () => scrollY.removeListener(listener);
|
|
58
|
+
}, [isDark, threshold, style, scrollY]);
|
|
59
|
+
|
|
60
|
+
const backgroundOpacity = scrollY.interpolate({
|
|
61
|
+
inputRange: [threshold - 40, threshold],
|
|
62
|
+
outputRange: [0, 1],
|
|
63
|
+
extrapolate: 'clamp',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const activeStyle = isDark ? 'light' : style;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<StatusBar style={activeStyle} />
|
|
71
|
+
<Animated.View
|
|
72
|
+
style={[
|
|
73
|
+
styles.background,
|
|
74
|
+
{
|
|
75
|
+
height: insets.top,
|
|
76
|
+
backgroundColor: colors.background,
|
|
77
|
+
opacity: backgroundOpacity,
|
|
78
|
+
},
|
|
79
|
+
]}
|
|
80
|
+
/>
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const styles = StyleSheet.create({
|
|
86
|
+
background: {
|
|
87
|
+
position: 'absolute',
|
|
88
|
+
top: 0,
|
|
89
|
+
left: 0,
|
|
90
|
+
right: 0,
|
|
91
|
+
zIndex: 100,
|
|
92
|
+
},
|
|
93
|
+
});
|