@snap/valdi 1.0.8 → 1.1.5
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/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
- package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
- package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
- package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.metadata/.bazelrc.template +92 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.editorconfig.template +37 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/AGENTS.md.template +16 -0
- package/.metadata/MODULE.bazel.template +62 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.metadata/skill-reference.tsx.template +8 -0
- package/.metadata/skill-tests-BUILD.bazel.template +21 -0
- package/.metadata/skill-tests-README.md.template +17 -0
- package/.metadata/skill.md.template +27 -0
- package/bundled-skills/registry.json +14 -2
- package/bundled-skills/skills/valdi-animations/skill.md +197 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
- package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
- package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +49 -5
- package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
- package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +217 -0
- package/bundled-skills/skills/valdi-localization/skill.md +142 -0
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
- package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
- package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
- package/bundled-skills/skills/valdi-overview/skill.md +7 -4
- package/bundled-skills/skills/valdi-perf/skill.md +223 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +131 -12
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-profile/skill.md +126 -0
- package/bundled-skills/skills/valdi-setup/skill.md +55 -5
- package/bundled-skills/skills/valdi-testing/skill.md +23 -7
- package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
- package/dist/commands/agentCheck.js +184 -0
- package/dist/commands/analyze.js +16 -0
- package/dist/commands/analyze_commands/duplicates.js +134 -0
- package/dist/commands/bootstrap.js +57 -73
- package/dist/commands/doctor.js +40 -203
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/inspect_commands/contexts.js +55 -0
- package/dist/commands/inspect_commands/devices.js +53 -0
- package/dist/commands/inspect_commands/heap.js +59 -0
- package/dist/commands/inspect_commands/select.js +43 -0
- package/dist/commands/inspect_commands/snapshot.js +129 -0
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/inspect_commands/status.js +68 -0
- package/dist/commands/inspect_commands/tree.js +86 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/profile.js +16 -0
- package/dist/commands/profile_commands/capture.js +106 -0
- package/dist/commands/projectsync.js +9 -7
- package/dist/commands/skills_commands/install.js +6 -1
- package/dist/commands/skills_commands/update.js +2 -1
- package/dist/core/analyze/clusterer.js +150 -0
- package/dist/core/analyze/fingerprint.js +2 -0
- package/dist/core/analyze/knownPatterns.js +76 -0
- package/dist/core/analyze/parser.js +177 -0
- package/dist/core/analyze/reporter.js +83 -0
- package/dist/core/analyze/scanner.js +172 -0
- package/dist/core/analyze/similarity.js +56 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/packageFiles.spec.js +29 -0
- package/dist/preview/previewGenerator.js +240 -0
- package/dist/preview/previewGenerator.spec.js +203 -0
- package/dist/preview/viewModelParser.js +86 -0
- package/dist/preview/viewModelParser.spec.js +171 -0
- package/dist/setup/DevSetupHelper.js +0 -51
- package/dist/setup/linuxSetup.js +0 -2
- package/dist/setup/macOSSetup.js +1 -4
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/daemonClient.js +344 -0
- package/dist/utils/hermesClient.js +252 -0
- package/dist/utils/skillsAdapters.js +86 -5
- package/dist/utils/skillsAdapters.spec.js +60 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/dist/utils/stringUtils.spec.js +1 -1
- package/package.json +30 -12
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello world!');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
root: true,
|
|
4
|
+
parser: '@typescript-eslint/parser',
|
|
5
|
+
parserOptions: {
|
|
6
|
+
tsconfigRootDir: __dirname,
|
|
7
|
+
project: ['./src/valdi/_configs/eslint.tsconfig.json'],
|
|
8
|
+
},
|
|
9
|
+
plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snapchat/eslint-plugin-valdi'],
|
|
10
|
+
extends: [
|
|
11
|
+
'eslint:recommended',
|
|
12
|
+
'plugin:@typescript-eslint/recommended',
|
|
13
|
+
'plugin:import/recommended',
|
|
14
|
+
'plugin:import/typescript',
|
|
15
|
+
'prettier',
|
|
16
|
+
],
|
|
17
|
+
rules: {
|
|
18
|
+
'@snapchat/valdi/attributed-text-no-array-assignment': 'error',
|
|
19
|
+
'@snapchat/valdi/jsx-no-lambda': 'error',
|
|
20
|
+
'@snapchat/valdi/assign-timer-id': 'error',
|
|
21
|
+
'@snapchat/valdi/only-const-enum': 'off',
|
|
22
|
+
'@snapchat/valdi/no-implicit-index-import': 'error',
|
|
23
|
+
'@snapchat/valdi/mutate-state-without-set-state': 'error',
|
|
24
|
+
'@snapchat/valdi/no-import-from-test-outside-test-dir': 'error',
|
|
25
|
+
'@snapchat/valdi/no-declare-test-without-describe': 'error',
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_application.bzl", "valdi_application")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_exported_library.bzl", "valdi_exported_library")
|
|
3
|
+
|
|
4
|
+
valdi_application(
|
|
5
|
+
name = "{{MODULE_NAME}}_app",
|
|
6
|
+
ios_bundle_id = "com.website.{{MODULE_NAME}}",
|
|
7
|
+
ios_families = ["iphone"],
|
|
8
|
+
root_component_path = "App@{{MODULE_NAME}}/src/App",
|
|
9
|
+
title = "{{MODULE_NAME}}",
|
|
10
|
+
version = "1.0.0",
|
|
11
|
+
deps = ["//modules/{{MODULE_NAME}}"],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
valdi_exported_library(
|
|
15
|
+
name = "{{MODULE_NAME}}_export",
|
|
16
|
+
ios_bundle_id = "com.website.{{MODULE_NAME}}.lib",
|
|
17
|
+
ios_bundle_name = "{{MODULE_NAME_PASCAL_CASED}}",
|
|
18
|
+
deps = ["//modules/{{MODULE_NAME}}"],
|
|
19
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
2
|
+
|
|
3
|
+
valdi_module(
|
|
4
|
+
name = "{{MODULE_NAME}}",
|
|
5
|
+
srcs = glob([
|
|
6
|
+
"src/**/*.ts",
|
|
7
|
+
"src/**/*.tsx",
|
|
8
|
+
]),
|
|
9
|
+
res = glob([
|
|
10
|
+
"res/**/*.jpeg",
|
|
11
|
+
"res/**/*.jpg",
|
|
12
|
+
"res/**/*.png",
|
|
13
|
+
"res/**/*.svg",
|
|
14
|
+
"res/**/*.webp",
|
|
15
|
+
]),
|
|
16
|
+
visibility = ["//visibility:public"],
|
|
17
|
+
deps = [
|
|
18
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_core",
|
|
19
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_tsx",
|
|
20
|
+
],
|
|
21
|
+
)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
2
|
+
import { ImageView, Label, View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
3
|
+
import { Style } from 'valdi_core/src/Style';
|
|
4
|
+
import { systemBoldFont, systemFont } from 'valdi_core/src/SystemFont';
|
|
5
|
+
import { AttributedText } from 'valdi_tsx/src/AttributedText';
|
|
6
|
+
import { AttributedTextBuilder } from 'valdi_core/src/utils/AttributedTextBuilder';
|
|
7
|
+
import { Device } from 'valdi_core/src/Device';
|
|
8
|
+
import { getDaemonClientManager } from 'valdi_core/src/debugging/DaemonClientManagerResolver';
|
|
9
|
+
import { IDaemonClientManagerListener } from 'valdi_core/src/debugging/DaemonClientManager';
|
|
10
|
+
import res from '../res';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ViewModel
|
|
14
|
+
* @ExportModel
|
|
15
|
+
*/
|
|
16
|
+
export interface AppViewModel {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @Context
|
|
20
|
+
* @ExportModel
|
|
21
|
+
*/
|
|
22
|
+
export interface AppComponentContext {}
|
|
23
|
+
|
|
24
|
+
interface State {
|
|
25
|
+
hotReloaderConnected: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @Component
|
|
30
|
+
* @ExportModel
|
|
31
|
+
*/
|
|
32
|
+
export class App extends StatefulComponent<AppViewModel, AppComponentContext> implements IDaemonClientManagerListener {
|
|
33
|
+
state: State = { hotReloaderConnected: false };
|
|
34
|
+
|
|
35
|
+
onCreate(): void {
|
|
36
|
+
console.log('On App create!');
|
|
37
|
+
getDaemonClientManager().addListener(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onDestroy(): void {
|
|
41
|
+
console.log('On App destroy!');
|
|
42
|
+
getDaemonClientManager().removeListener(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onAvailabilityChanged(available: boolean): void {
|
|
46
|
+
this.setState({ hotReloaderConnected: available });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onRender(): void {
|
|
50
|
+
console.log('On App render!');
|
|
51
|
+
<view style={styles.main}>
|
|
52
|
+
<image style={styles.logo} src={res.valdi} />
|
|
53
|
+
<layout padding={20}>
|
|
54
|
+
<label style={styles.title} value={`Welcome to Valdi!`} />
|
|
55
|
+
</layout>
|
|
56
|
+
<label style={styles.subtitle} value={this.renderLabel()} />
|
|
57
|
+
</view>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private renderLabel(): AttributedText {
|
|
61
|
+
const textBuilder = new AttributedTextBuilder();
|
|
62
|
+
|
|
63
|
+
textBuilder.appendText('This is currently running on ');
|
|
64
|
+
textBuilder.appendStyled({
|
|
65
|
+
content: this.getPlatformString(),
|
|
66
|
+
attributes: {
|
|
67
|
+
color: 'red',
|
|
68
|
+
font: systemBoldFont(20),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
textBuilder.appendText('\nHot reloader ');
|
|
73
|
+
if (this.state.hotReloaderConnected) {
|
|
74
|
+
textBuilder.appendStyled({
|
|
75
|
+
content: 'connected',
|
|
76
|
+
attributes: {
|
|
77
|
+
color: 'green',
|
|
78
|
+
font: systemBoldFont(20),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
textBuilder.appendStyled({
|
|
83
|
+
content: 'disconnected',
|
|
84
|
+
attributes: {
|
|
85
|
+
color: 'red',
|
|
86
|
+
font: systemBoldFont(20),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return textBuilder.build();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private getPlatformString(): string {
|
|
95
|
+
if (Device.isDesktop()) {
|
|
96
|
+
return 'Desktop';
|
|
97
|
+
} else if (Device.isIOS()) {
|
|
98
|
+
return 'iOS';
|
|
99
|
+
} else if (Device.isAndroid()) {
|
|
100
|
+
return 'Android';
|
|
101
|
+
} else {
|
|
102
|
+
return 'Unknown';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const styles = {
|
|
108
|
+
main: new Style<View>({
|
|
109
|
+
backgroundColor: 'white',
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
}),
|
|
112
|
+
logo: new Style<ImageView>({
|
|
113
|
+
width: 80,
|
|
114
|
+
height: 80,
|
|
115
|
+
alignSelf: 'center',
|
|
116
|
+
borderRadius: 16,
|
|
117
|
+
boxShadow: '0 0 3 rgba(0, 0, 0, 0.15)',
|
|
118
|
+
}),
|
|
119
|
+
title: new Style<Label>({
|
|
120
|
+
color: 'black',
|
|
121
|
+
font: systemBoldFont(24),
|
|
122
|
+
accessibilityCategory: 'header',
|
|
123
|
+
alignSelf: 'center',
|
|
124
|
+
}),
|
|
125
|
+
|
|
126
|
+
subtitle: new Style<Label>({
|
|
127
|
+
alignSelf: 'center',
|
|
128
|
+
color: 'black',
|
|
129
|
+
font: systemFont(20),
|
|
130
|
+
numberOfLines: 0,
|
|
131
|
+
textAlign: 'center',
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hello_world",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Valdi Helloworld app",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@snap/eslint-plugin-valdi": "1.0.2",
|
|
8
|
+
"@types/eslint": "^9.6.1",
|
|
9
|
+
"@types/jasmine": "^5.1.7",
|
|
10
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
11
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
12
|
+
"@typescript-eslint/utils": "^6.21.0",
|
|
13
|
+
"eslint": "^8.27.0",
|
|
14
|
+
"eslint-config-prettier": "^8.5.0",
|
|
15
|
+
"eslint-plugin-import": "^2.26.0",
|
|
16
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
17
|
+
"eslint-plugin-rxjs": "^5.0.2",
|
|
18
|
+
"eslint-plugin-unused-imports": "^3.2.0",
|
|
19
|
+
"jasmine": "^5.6.0",
|
|
20
|
+
"ts-node": "^10.9.2",
|
|
21
|
+
"typescript": "5.3.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_android_library.bzl", "valdi_android_library")
|
|
3
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
4
|
+
|
|
5
|
+
valdi_android_library(
|
|
6
|
+
name = "android_impl",
|
|
7
|
+
srcs = glob([
|
|
8
|
+
"android/**/*.kt",
|
|
9
|
+
]),
|
|
10
|
+
deps = [
|
|
11
|
+
":{{MODULE_NAME}}_api_kt",
|
|
12
|
+
],
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
objc_library(
|
|
16
|
+
name = "ios_impl",
|
|
17
|
+
srcs = glob([
|
|
18
|
+
"ios/**/*.m",
|
|
19
|
+
]),
|
|
20
|
+
hdrs = glob([
|
|
21
|
+
"ios/**/*.h",
|
|
22
|
+
]),
|
|
23
|
+
copts = ["-I."],
|
|
24
|
+
deps = [
|
|
25
|
+
":{{MODULE_NAME}}_api_objc",
|
|
26
|
+
],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
ts_project(
|
|
30
|
+
name = "{{MODULE_NAME}}_web",
|
|
31
|
+
srcs = glob([
|
|
32
|
+
"web/**/*.ts",
|
|
33
|
+
"web/**/*.d.ts",
|
|
34
|
+
]),
|
|
35
|
+
allow_js = True,
|
|
36
|
+
composite = False,
|
|
37
|
+
transpiler = "tsc",
|
|
38
|
+
tsconfig = "web/tsconfig.json",
|
|
39
|
+
visibility = ["//visibility:public"],
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
valdi_module(
|
|
43
|
+
name = "{{MODULE_NAME}}",
|
|
44
|
+
srcs = glob([
|
|
45
|
+
"src/**/*.ts",
|
|
46
|
+
"src/**/*.tsx",
|
|
47
|
+
]),
|
|
48
|
+
android_deps = [":android_impl"],
|
|
49
|
+
ios_deps = [":ios_impl"],
|
|
50
|
+
ios_module_name = "{{MODULE_NAME_PASCAL_CASED}}",
|
|
51
|
+
visibility = ["//visibility:public"],
|
|
52
|
+
web_deps = [":{{MODULE_NAME}}_web"],
|
|
53
|
+
deps = [],
|
|
54
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.snap.modules.{{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
import com.snapchat.client.valdi_core.ModuleFactory
|
|
4
|
+
import com.snap.valdi.modules.RegisterValdiModule
|
|
5
|
+
import com.snap.modules.{{MODULE_NAME}}.CalculatorModuleFactory
|
|
6
|
+
import com.snap.modules.{{MODULE_NAME}}.CalculatorModule
|
|
7
|
+
|
|
8
|
+
@RegisterValdiModule
|
|
9
|
+
class CalculatorModuleFactoryImpl: CalculatorModuleFactory() {
|
|
10
|
+
|
|
11
|
+
override fun onLoadModule(): CalculatorModule {
|
|
12
|
+
return object: CalculatorModule {
|
|
13
|
+
override fun multiply(left: Double, right: Double): Double {
|
|
14
|
+
return left * right
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#import "valdi_core/SCValdiModuleFactoryRegistry.h"
|
|
2
|
+
#import <{{MODULE_NAME_PASCAL_CASED}}Types/{{MODULE_NAME_PASCAL_CASED}}Types.h>
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
|
|
5
|
+
@interface SCCCalculatorModule: NSObject<{{MODULE_NAME_PASCAL_CASED}}CalculatorModule>
|
|
6
|
+
|
|
7
|
+
@end
|
|
8
|
+
|
|
9
|
+
@implementation SCCCalculatorModule
|
|
10
|
+
|
|
11
|
+
- (double)multiplyWithLeft:(double)left right:(double)right
|
|
12
|
+
{
|
|
13
|
+
return left * right;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@interface SCCCalculatorModuleFactoryImpl : {{MODULE_NAME_PASCAL_CASED}}CalculatorModuleFactory
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@implementation SCCCalculatorModuleFactoryImpl
|
|
23
|
+
|
|
24
|
+
VALDI_REGISTER_MODULE()
|
|
25
|
+
|
|
26
|
+
- (id<{{MODULE_NAME_PASCAL_CASED}}CalculatorModule>)onLoadModule
|
|
27
|
+
{
|
|
28
|
+
return [SCCCalculatorModule new];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web implementation of the Calculator bridge module.
|
|
3
|
+
*
|
|
4
|
+
* Registered automatically by RegisterNativeModules.js via moduleLoader.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function multiply(left: number, right: number): number {
|
|
8
|
+
return left * right;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export = { multiply };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"lib": ["DOM", "ES2020"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"composite": false,
|
|
10
|
+
"allowJs": true
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"./**/*.ts",
|
|
14
|
+
"./**/*.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_android_library.bzl", "valdi_android_library")
|
|
3
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
4
|
+
|
|
5
|
+
valdi_android_library(
|
|
6
|
+
name = "android_impl",
|
|
7
|
+
srcs = glob([
|
|
8
|
+
"android/**/*.kt",
|
|
9
|
+
]),
|
|
10
|
+
visibility = ["//visibility:public"],
|
|
11
|
+
deps = [
|
|
12
|
+
":{{MODULE_NAME}}_api_kt",
|
|
13
|
+
"@valdi//valdi:valdi_java",
|
|
14
|
+
],
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
objc_library(
|
|
18
|
+
name = "ios_impl",
|
|
19
|
+
srcs = glob([
|
|
20
|
+
"ios/**/*.m",
|
|
21
|
+
]),
|
|
22
|
+
hdrs = glob([
|
|
23
|
+
"ios/**/*.h",
|
|
24
|
+
]),
|
|
25
|
+
copts = ["-I."],
|
|
26
|
+
visibility = ["//visibility:public"],
|
|
27
|
+
deps = [
|
|
28
|
+
":{{MODULE_NAME}}_api_objc",
|
|
29
|
+
],
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
objc_library(
|
|
33
|
+
name = "macos_impl",
|
|
34
|
+
srcs = glob([
|
|
35
|
+
"macos/**/*.m",
|
|
36
|
+
]),
|
|
37
|
+
hdrs = glob([
|
|
38
|
+
"macos/**/*.h",
|
|
39
|
+
]),
|
|
40
|
+
copts = ["-I."],
|
|
41
|
+
sdk_frameworks = ["AppKit"],
|
|
42
|
+
visibility = ["//visibility:public"],
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
ts_project(
|
|
46
|
+
name = "{{MODULE_NAME}}_web",
|
|
47
|
+
srcs = glob([
|
|
48
|
+
"web/**/*.ts",
|
|
49
|
+
"web/**/*.d.ts",
|
|
50
|
+
]),
|
|
51
|
+
allow_js = True,
|
|
52
|
+
composite = False,
|
|
53
|
+
transpiler = "tsc",
|
|
54
|
+
tsconfig = "web/tsconfig.json",
|
|
55
|
+
visibility = ["//visibility:public"],
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
valdi_module(
|
|
59
|
+
name = "{{MODULE_NAME}}",
|
|
60
|
+
srcs = glob([
|
|
61
|
+
"src/**/*.ts",
|
|
62
|
+
"src/**/*.tsx",
|
|
63
|
+
]),
|
|
64
|
+
android_deps = [":android_impl"],
|
|
65
|
+
ios_deps = [":ios_impl"],
|
|
66
|
+
ios_module_name = "SCC{{MODULE_NAME_PASCAL_CASED}}",
|
|
67
|
+
macos_deps = [":macos_impl"],
|
|
68
|
+
visibility = ["//visibility:public"],
|
|
69
|
+
web_deps = [":{{MODULE_NAME}}_web"],
|
|
70
|
+
deps = [
|
|
71
|
+
"@valdi//src/valdi_modules/src/valdi/foundation",
|
|
72
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_core",
|
|
73
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_tsx",
|
|
74
|
+
],
|
|
75
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.snap.modules.{{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.view.MotionEvent
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import android.widget.LinearLayout
|
|
8
|
+
import android.widget.TextView
|
|
9
|
+
import com.snap.valdi.views.ValdiTouchEventResult
|
|
10
|
+
import com.snap.valdi.views.ValdiTouchTarget
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Android native view for the {{MODULE_NAME}} polyglot module.
|
|
14
|
+
* ReflectionViewFactory requires a single-arg (Context) constructor.
|
|
15
|
+
*/
|
|
16
|
+
class PolyglotNativeView(context: Context) : LinearLayout(context), ValdiTouchTarget {
|
|
17
|
+
|
|
18
|
+
init {
|
|
19
|
+
orientation = VERTICAL
|
|
20
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
21
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
22
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
|
23
|
+
)
|
|
24
|
+
setBackgroundColor(Color.parseColor("#E8E8E8"))
|
|
25
|
+
|
|
26
|
+
val label = TextView(context).apply {
|
|
27
|
+
text = "Hello from Android ({{MODULE_NAME}})"
|
|
28
|
+
setPadding(32, 32, 32, 16)
|
|
29
|
+
}
|
|
30
|
+
addView(label)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun processTouchEvent(event: MotionEvent): ValdiTouchEventResult {
|
|
34
|
+
val consumed = dispatchTouchEvent(event)
|
|
35
|
+
return if (consumed) {
|
|
36
|
+
ValdiTouchEventResult.ConsumeEventAndCancelOtherGestures
|
|
37
|
+
} else {
|
|
38
|
+
ValdiTouchEventResult.IgnoreEvent
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.snap.modules.{{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.snap.valdi.attributes.AttributesBinder
|
|
5
|
+
import com.snap.valdi.attributes.AttributesBindingContext
|
|
6
|
+
import com.snap.valdi.attributes.RegisterAttributesBinder
|
|
7
|
+
|
|
8
|
+
@RegisterAttributesBinder
|
|
9
|
+
class PolyglotNativeViewAttributesBinder constructor(private val context: Context) : AttributesBinder<PolyglotNativeView> {
|
|
10
|
+
|
|
11
|
+
override val viewClass: Class<PolyglotNativeView>
|
|
12
|
+
get() = PolyglotNativeView::class.java
|
|
13
|
+
|
|
14
|
+
override fun bindAttributes(attributesBindingContext: AttributesBindingContext<PolyglotNativeView>) {
|
|
15
|
+
// Add custom attribute bindings here.
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#import "SCPolyglotView.h"
|
|
2
|
+
|
|
3
|
+
@implementation SCPolyglotView
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
6
|
+
self = [super initWithFrame:frame];
|
|
7
|
+
if (self) {
|
|
8
|
+
self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
|
|
9
|
+
|
|
10
|
+
UILabel *label = [[UILabel alloc] init];
|
|
11
|
+
label.text = @"Hello from iOS";
|
|
12
|
+
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
13
|
+
[self addSubview:label];
|
|
14
|
+
|
|
15
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
16
|
+
[label.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
|
|
17
|
+
[label.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
|
|
18
|
+
]];
|
|
19
|
+
}
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#import "SCPolyglotView.h"
|
|
2
|
+
|
|
3
|
+
@implementation SCPolyglotView
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithFrame:(NSRect)frameRect {
|
|
6
|
+
self = [super initWithFrame:frameRect];
|
|
7
|
+
if (self) {
|
|
8
|
+
self.wantsLayer = YES;
|
|
9
|
+
self.layer.backgroundColor = [[NSColor colorWithWhite:0.93 alpha:1] CGColor];
|
|
10
|
+
|
|
11
|
+
NSTextField *label = [NSTextField labelWithString:@"Hello from macOS"];
|
|
12
|
+
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
13
|
+
[self addSubview:label];
|
|
14
|
+
|
|
15
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
16
|
+
[label.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
|
|
17
|
+
[label.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
|
|
18
|
+
]];
|
|
19
|
+
}
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'valdi_tsx/src/JSX';
|
|
2
|
+
import { View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
3
|
+
|
|
4
|
+
export interface PolyglotCustomViewModel extends View {}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Polyglot custom-view wrapper.
|
|
8
|
+
*
|
|
9
|
+
* Each platform resolves the view by class name:
|
|
10
|
+
* - Android: ReflectionViewFactory creates PolyglotNativeView(context)
|
|
11
|
+
* - iOS: ObjC class linked via ios_deps
|
|
12
|
+
* - macOS: NSClassFromString() linked via macos_deps
|
|
13
|
+
* - Web: webPolyglotViews factory in web/ auto-registered at bundle time
|
|
14
|
+
*/
|
|
15
|
+
export function PolyglotCustomView(viewModel: PolyglotCustomViewModel) {
|
|
16
|
+
<custom-view
|
|
17
|
+
androidClass={'com.snap.modules.{{MODULE_NAME}}.PolyglotNativeView'}
|
|
18
|
+
iosClass={'SCPolyglotView'}
|
|
19
|
+
macosClass={'SCPolyglotView'}
|
|
20
|
+
webClass={'{{MODULE_NAME_PASCAL_CASED}}WebView'}
|
|
21
|
+
{...viewModel}
|
|
22
|
+
/>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web polyglot entry for {{MODULE_NAME}}.
|
|
3
|
+
*
|
|
4
|
+
* Exports view factories that are auto-registered with the WebViewClassRegistry
|
|
5
|
+
* by the build-generated RegisterNativeModules.js.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function createWebViewFactory(): (container: HTMLElement) => void {
|
|
9
|
+
return (container: HTMLElement) => {
|
|
10
|
+
container.style.display = 'flex';
|
|
11
|
+
container.style.alignItems = 'center';
|
|
12
|
+
container.style.justifyContent = 'center';
|
|
13
|
+
container.style.padding = '12px';
|
|
14
|
+
container.style.backgroundColor = '#f8f9fa';
|
|
15
|
+
container.style.borderRadius = '8px';
|
|
16
|
+
container.style.border = '1px solid #ccc';
|
|
17
|
+
container.style.minHeight = '80px';
|
|
18
|
+
|
|
19
|
+
const label = document.createElement('span');
|
|
20
|
+
label.textContent = 'Hello from Web ({{MODULE_NAME}})';
|
|
21
|
+
label.style.fontSize = '14px';
|
|
22
|
+
label.style.fontWeight = '500';
|
|
23
|
+
container.appendChild(label);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const webPolyglotViews: Record<string, (container: HTMLElement) => void> = {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
29
|
+
{{MODULE_NAME_PASCAL_CASED}}WebView: createWebViewFactory(),
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"lib": ["DOM", "ES2020"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"composite": false,
|
|
10
|
+
"allowJs": true
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"./**/*.ts",
|
|
14
|
+
"./**/*.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|