@snap/valdi 1.0.1
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/.bazelignore +2 -0
- package/.bootstrap/apps/cli_application/AGENTS.md.template +215 -0
- 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/AGENTS.md.template +202 -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/cpp_bridge_module/BUILD.bazel.template +21 -0
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +29 -0
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +1 -0
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +39 -0
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +41 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +42 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +60 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +6 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +82 -0
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +15 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.config/copyconfig.json +10 -0
- package/.editorconfig +21 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +72 -0
- package/.metadata/.bazelrc.template +91 -0
- package/.metadata/.bazelversion.template +1 -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/README.md.template +31 -0
- package/.metadata/WORKSPACE.template +57 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +7 -0
- package/README.md +123 -0
- package/dist/commands/bootstrap.js +233 -0
- package/dist/commands/build.js +67 -0
- package/dist/commands/devSetup.js +18 -0
- package/dist/commands/doctor.js +892 -0
- package/dist/commands/export.js +84 -0
- package/dist/commands/hotreload.js +89 -0
- package/dist/commands/install.js +71 -0
- package/dist/commands/lint.js +18 -0
- package/dist/commands/lint_commands/lintCheck.js +31 -0
- package/dist/commands/lint_commands/lintFormat.js +31 -0
- package/dist/commands/log.js +84 -0
- package/dist/commands/newModule.js +208 -0
- package/dist/commands/package.js +66 -0
- package/dist/commands/projectsync.js +316 -0
- package/dist/commands/test.js +54 -0
- package/dist/core/constants.js +76 -0
- package/dist/core/errors.js +12 -0
- package/dist/index.js +22 -0
- package/dist/setup/DevSetupHelper.js +146 -0
- package/dist/setup/linuxSetup.js +31 -0
- package/dist/setup/macOSSetup.js +35 -0
- package/dist/setup/setupEntryPoint.js +56 -0
- package/dist/setup/versions.js +8 -0
- package/dist/utils/ArgumentsResolver.js +23 -0
- package/dist/utils/BazelClient.js +219 -0
- package/dist/utils/Digraph.js +71 -0
- package/dist/utils/LoadingIndicator.js +38 -0
- package/dist/utils/applicationUtils.js +201 -0
- package/dist/utils/buildInfo.js +60 -0
- package/dist/utils/byString.js +6 -0
- package/dist/utils/cliUtils.js +93 -0
- package/dist/utils/copyBootstrapFiles.js +26 -0
- package/dist/utils/deviceUtils.js +72 -0
- package/dist/utils/errorUtils.js +55 -0
- package/dist/utils/fileUtils.js +204 -0
- package/dist/utils/githubUtils.js +8 -0
- package/dist/utils/jsonUtils.js +28 -0
- package/dist/utils/lintUtils.js +149 -0
- package/dist/utils/logUtils.js +8 -0
- package/dist/utils/pathUtils.js +12 -0
- package/dist/utils/stringUtils.js +17 -0
- package/dist/utils/stringUtils.spec.js +18 -0
- package/dist/utils/tempDir.js +26 -0
- package/dist/utils/zipUtils.js +16 -0
- package/package.json +51 -0
- package/prettier.config.js +4 -0
- package/spec/support/jasmine.json +6 -0
- package/src/commands/bootstrap.ts +317 -0
- package/src/commands/build.ts +89 -0
- package/src/commands/devSetup.ts +17 -0
- package/src/commands/doctor.ts +1422 -0
- package/src/commands/export.ts +131 -0
- package/src/commands/hotreload.ts +108 -0
- package/src/commands/install.ts +93 -0
- package/src/commands/lint.ts +15 -0
- package/src/commands/lint_commands/lintCheck.ts +53 -0
- package/src/commands/lint_commands/lintFormat.ts +49 -0
- package/src/commands/log.ts +108 -0
- package/src/commands/newModule.ts +287 -0
- package/src/commands/package.ts +102 -0
- package/src/commands/projectsync.ts +488 -0
- package/src/commands/test.ts +68 -0
- package/src/core/constants.ts +95 -0
- package/src/core/errors.ts +10 -0
- package/src/index.ts +22 -0
- package/src/setup/DevSetupHelper.ts +188 -0
- package/src/setup/linuxSetup.ts +38 -0
- package/src/setup/macOSSetup.ts +42 -0
- package/src/setup/setupEntryPoint.ts +64 -0
- package/src/setup/versions.ts +8 -0
- package/src/utils/ArgumentsResolver.ts +23 -0
- package/src/utils/BazelClient.ts +285 -0
- package/src/utils/Digraph.ts +81 -0
- package/src/utils/LoadingIndicator.ts +43 -0
- package/src/utils/applicationUtils.ts +276 -0
- package/src/utils/buildInfo.ts +99 -0
- package/src/utils/byString.ts +3 -0
- package/src/utils/cliUtils.ts +112 -0
- package/src/utils/copyBootstrapFiles.ts +30 -0
- package/src/utils/deviceUtils.ts +76 -0
- package/src/utils/errorUtils.ts +63 -0
- package/src/utils/fileUtils.ts +257 -0
- package/src/utils/githubUtils.ts +6 -0
- package/src/utils/jsonUtils.ts +30 -0
- package/src/utils/lintUtils.ts +190 -0
- package/src/utils/logUtils.ts +9 -0
- package/src/utils/pathUtils.ts +12 -0
- package/src/utils/stringUtils.spec.ts +19 -0
- package/src/utils/stringUtils.ts +15 -0
- package/src/utils/tempDir.ts +24 -0
- package/src/utils/zipUtils.ts +14 -0
- package/test/ValdiSmokeTest.ts +278 -0
- package/test/helpers/AsyncHelpers.ts +113 -0
- package/test/helpers/CommandHelpers.ts +37 -0
- package/test/helpers/ProjectHelpers.ts +153 -0
- package/test/helpers/StreamHelpers.ts +37 -0
- package/test/helpers/TypeScriptClient.ts +217 -0
- package/tsconfig.dist.json +8 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#include "valdi_core/cpp/JavaScript/ModuleFactoryRegistry.hpp"
|
|
2
|
+
#include "valdi_core/cpp/Utils/ValueFunctionWithCallable.hpp"
|
|
3
|
+
|
|
4
|
+
namespace snap::valdi::{{MODULE_NAME}} {
|
|
5
|
+
|
|
6
|
+
class CalculatorModuleFactory : public valdi_core::ModuleFactory {
|
|
7
|
+
public:
|
|
8
|
+
CalculatorModuleFactory() = default;
|
|
9
|
+
~CalculatorModuleFactory() override = default;
|
|
10
|
+
|
|
11
|
+
Valdi::StringBox getModulePath() final {
|
|
12
|
+
return Valdi::StringBox::fromCString("{{MODULE_NAME}}/src/Calculator");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Valdi::Value loadModule() final {
|
|
16
|
+
return Valdi::Value().setMapValue("multiply",
|
|
17
|
+
Valdi::Value(Valdi::makeShared<Valdi::ValueFunctionWithCallable>(
|
|
18
|
+
[](const Valdi::ValueFunctionCallContext& callContext) -> Valdi::Value {
|
|
19
|
+
auto left = callContext.getParameterAsDouble(0);
|
|
20
|
+
auto right = callContext.getParameterAsDouble(1);
|
|
21
|
+
|
|
22
|
+
return Valdi::Value(left * right);
|
|
23
|
+
})));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
Valdi::RegisterModuleFactory kRegisterCalculatorModuleFactory([]() { return std::make_shared<CalculatorModuleFactory>(); });
|
|
28
|
+
|
|
29
|
+
} // namespace snap::valdi::{{MODULE_NAME}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function multiply(left: number, right: number): number;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_android_library.bzl", "valdi_android_library")
|
|
3
|
+
|
|
4
|
+
valdi_android_library(
|
|
5
|
+
name = "android_impl",
|
|
6
|
+
srcs = glob([
|
|
7
|
+
"android/**/*.kt",
|
|
8
|
+
]),
|
|
9
|
+
deps = [
|
|
10
|
+
":{{MODULE_NAME}}_api_kt",
|
|
11
|
+
],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
objc_library(
|
|
15
|
+
name = "ios_impl",
|
|
16
|
+
srcs = glob([
|
|
17
|
+
"ios/**/*.m",
|
|
18
|
+
]),
|
|
19
|
+
hdrs = glob([
|
|
20
|
+
"ios/**/*.h",
|
|
21
|
+
]),
|
|
22
|
+
copts = ["-I."],
|
|
23
|
+
deps = [
|
|
24
|
+
":{{MODULE_NAME}}_api_objc",
|
|
25
|
+
],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
valdi_module(
|
|
29
|
+
name = "{{MODULE_NAME}}",
|
|
30
|
+
srcs = glob([
|
|
31
|
+
"src/**/*.ts",
|
|
32
|
+
"src/**/*.tsx",
|
|
33
|
+
]),
|
|
34
|
+
android_deps = [":android_impl"],
|
|
35
|
+
ios_deps = [":ios_impl"],
|
|
36
|
+
ios_module_name = "{{MODULE_NAME_PASCAL_CASED}}",
|
|
37
|
+
visibility = ["//visibility:public"],
|
|
38
|
+
deps = [],
|
|
39
|
+
)
|
package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template
ADDED
|
@@ -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
|
+
}
|
package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template
ADDED
|
@@ -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,41 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_android_library.bzl", "valdi_android_library")
|
|
3
|
+
|
|
4
|
+
valdi_android_library(
|
|
5
|
+
name = "android_impl",
|
|
6
|
+
srcs = glob([
|
|
7
|
+
"android/**/*.kt",
|
|
8
|
+
]),
|
|
9
|
+
deps = [
|
|
10
|
+
"@valdi//valdi:valdi_java",
|
|
11
|
+
],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
objc_library(
|
|
15
|
+
name = "ios_impl",
|
|
16
|
+
srcs = glob([
|
|
17
|
+
"ios/**/*.m",
|
|
18
|
+
]),
|
|
19
|
+
hdrs = glob([
|
|
20
|
+
"ios/**/*.h",
|
|
21
|
+
]),
|
|
22
|
+
copts = ["-I."],
|
|
23
|
+
deps = [
|
|
24
|
+
"@valdi//valdi_core",
|
|
25
|
+
],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
valdi_module(
|
|
29
|
+
name = "{{MODULE_NAME}}",
|
|
30
|
+
srcs = glob([
|
|
31
|
+
"src/**/*.ts",
|
|
32
|
+
"src/**/*.tsx",
|
|
33
|
+
]),
|
|
34
|
+
android_deps = [":android_impl"],
|
|
35
|
+
ios_deps = [":ios_impl"],
|
|
36
|
+
ios_module_name = "{{MODULE_NAME_PASCAL_CASED}}",
|
|
37
|
+
visibility = ["//visibility:public"],
|
|
38
|
+
deps = [
|
|
39
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_tsx",
|
|
40
|
+
],
|
|
41
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package com.snap.modules.{{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.*
|
|
5
|
+
import androidx.annotation.Keep
|
|
6
|
+
import com.snap.valdi.views.ValdiView
|
|
7
|
+
|
|
8
|
+
@Keep
|
|
9
|
+
class CircleView(context: Context): ValdiView(context) {
|
|
10
|
+
|
|
11
|
+
var ringThickness: Float
|
|
12
|
+
get() = paint.strokeWidth
|
|
13
|
+
set(value) {
|
|
14
|
+
this.paint.strokeWidth = value
|
|
15
|
+
invalidate()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var ringColor: Int
|
|
19
|
+
get() = this.paint.color
|
|
20
|
+
set(value) {
|
|
21
|
+
this.paint.color = value
|
|
22
|
+
invalidate()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private val paint = Paint().apply {
|
|
26
|
+
isAntiAlias = true
|
|
27
|
+
style = Paint.Style.STROKE
|
|
28
|
+
color = Color.TRANSPARENT
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
init {
|
|
32
|
+
setWillNotDraw(false)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun onDraw(canvas: Canvas) {
|
|
36
|
+
super.onDraw(canvas)
|
|
37
|
+
|
|
38
|
+
val halfThickness = ringThickness / 2f
|
|
39
|
+
|
|
40
|
+
canvas.drawOval(halfThickness, halfThickness, width.toFloat() - halfThickness, height.toFloat() - halfThickness, paint)
|
|
41
|
+
}
|
|
42
|
+
}
|
package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
package com.snap.modules.{{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.*
|
|
5
|
+
import android.view.View
|
|
6
|
+
import com.snap.valdi.attributes.*
|
|
7
|
+
import com.snap.valdi.attributes.impl.animations.ValdiAnimator
|
|
8
|
+
|
|
9
|
+
import com.snap.valdi.utils.CoordinateResolver
|
|
10
|
+
|
|
11
|
+
@RegisterAttributesBinder
|
|
12
|
+
class CircleViewAttributesBinder(context: Context): AttributesBinder<CircleView> {
|
|
13
|
+
|
|
14
|
+
private val coordinateResolver = CoordinateResolver(context)
|
|
15
|
+
|
|
16
|
+
override val viewClass: Class<CircleView>
|
|
17
|
+
get() = CircleView::class.java
|
|
18
|
+
|
|
19
|
+
fun applyThickness(view: CircleView, value: Float, @Suppress("UNUSED_PARAMETER") animator: ValdiAnimator?) {
|
|
20
|
+
val resolvedValue = coordinateResolver.toPixelF(value)
|
|
21
|
+
view.ringThickness = resolvedValue
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fun resetThickness(view: CircleView, @Suppress("UNUSED_PARAMETER") animator: ValdiAnimator?) {
|
|
25
|
+
view.ringThickness = 0f
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun applyColor(view: CircleView, value: Int, @Suppress("UNUSED_PARAMETER") animator: ValdiAnimator?) {
|
|
29
|
+
view.ringColor = value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun resetColor(view: CircleView, @Suppress("UNUSED_PARAMETER") animator: ValdiAnimator?) {
|
|
33
|
+
view.ringColor = Color.TRANSPARENT
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override fun bindAttributes(attributesBindingContext: AttributesBindingContext<CircleView>) {
|
|
37
|
+
attributesBindingContext.bindFloatAttribute("thickness", false, this::applyThickness, this::resetThickness)
|
|
38
|
+
attributesBindingContext.bindColorAttribute("color", false, this::applyColor, this::resetColor)
|
|
39
|
+
|
|
40
|
+
attributesBindingContext.setMeasureDelegate(object: MeasureDelegate {
|
|
41
|
+
override fun onMeasure(attributes: ViewLayoutAttributes,
|
|
42
|
+
widthMeasureSpec: Int,
|
|
43
|
+
heightMeasureSpec: Int,
|
|
44
|
+
isRightToLeft: Boolean): MeasuredSize {
|
|
45
|
+
val width = View.MeasureSpec.getSize(widthMeasureSpec)
|
|
46
|
+
val widthMode = View.MeasureSpec.getMode(widthMeasureSpec)
|
|
47
|
+
val height = View.MeasureSpec.getSize(heightMeasureSpec)
|
|
48
|
+
val heightMode = View.MeasureSpec.getMode(heightMeasureSpec)
|
|
49
|
+
|
|
50
|
+
if (widthMode == View.MeasureSpec.EXACTLY) {
|
|
51
|
+
return MeasuredSize(width, width)
|
|
52
|
+
} else if (heightMode == View.MeasureSpec.EXACTLY) {
|
|
53
|
+
return MeasuredSize(height, height)
|
|
54
|
+
} else {
|
|
55
|
+
return MeasuredSize(0, 0)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
#import "SCCCircleView.h"
|
|
3
|
+
#import "valdi_core/SCValdiAttributesBinderBase.h"
|
|
4
|
+
|
|
5
|
+
@implementation SCCCircleView {
|
|
6
|
+
CGFloat _thickness;
|
|
7
|
+
UIColor* _color;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
11
|
+
self = [super initWithFrame:frame];
|
|
12
|
+
|
|
13
|
+
if (self) {
|
|
14
|
+
self.opaque = NO;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return self;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (BOOL)willEnqueueIntoValdiPool {
|
|
21
|
+
return YES;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (void)drawRect:(CGRect)rect {
|
|
25
|
+
if (!_color) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
CGFloat halfLine = _thickness * 0.5f;
|
|
30
|
+
CGRect insetRect = CGRectInset(self.bounds, halfLine, halfLine);
|
|
31
|
+
|
|
32
|
+
UIBezierPath* circle = [UIBezierPath bezierPathWithOvalInRect:insetRect];
|
|
33
|
+
circle.lineWidth = _thickness;
|
|
34
|
+
|
|
35
|
+
[_color setStroke];
|
|
36
|
+
[circle stroke];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (BOOL)valdi_setThickness:(CGFloat)thickness {
|
|
40
|
+
_thickness = thickness;
|
|
41
|
+
[self setNeedsDisplay];
|
|
42
|
+
return YES;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (BOOL)valdi_setColor:(UIColor*)color {
|
|
46
|
+
_color = color;
|
|
47
|
+
[self setNeedsDisplay];
|
|
48
|
+
return YES;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
+ (CGSize)valdi_onMeasureWithAttributes:(id<SCValdiViewLayoutAttributes>)attributes maxSize:(CGSize)maxSize {
|
|
52
|
+
CGFloat minSize = MIN(maxSize.width, maxSize.height);
|
|
53
|
+
return CGSizeMake(minSize, minSize);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
+ (void)bindAttributes:(id<SCValdiAttributesBinderProtocol>)attributesBinder {
|
|
57
|
+
[attributesBinder bindAttribute:@"thickness"
|
|
58
|
+
invalidateLayoutOnChange:NO
|
|
59
|
+
withDoubleBlock:^BOOL(__kindof UIView* view, CGFloat attributeValue, id<SCValdiAnimatorProtocol> animator) {
|
|
60
|
+
return [view valdi_setThickness:attributeValue];
|
|
61
|
+
}
|
|
62
|
+
resetBlock:^(__kindof UIView* view, id<SCValdiAnimatorProtocol> animator) {
|
|
63
|
+
[view valdi_setThickness:0];
|
|
64
|
+
}];
|
|
65
|
+
|
|
66
|
+
[attributesBinder bindAttribute:@"color"
|
|
67
|
+
invalidateLayoutOnChange:NO
|
|
68
|
+
withColorBlock:^BOOL(__kindof UIView* view, UIColor* attributeValue, id<SCValdiAnimatorProtocol> animator) {
|
|
69
|
+
return [view valdi_setColor:attributeValue];
|
|
70
|
+
}
|
|
71
|
+
resetBlock:^(__kindof UIView* view, id<SCValdiAnimatorProtocol> animator) {
|
|
72
|
+
[view valdi_setColor:nil];
|
|
73
|
+
}];
|
|
74
|
+
|
|
75
|
+
[attributesBinder setMeasureDelegate:^CGSize(id<SCValdiViewLayoutAttributes> attributes,
|
|
76
|
+
CGSize maxSize,
|
|
77
|
+
UITraitCollection* traitCollection) {
|
|
78
|
+
return [SCCCircleView valdi_onMeasureWithAttributes:attributes maxSize:maxSize];
|
|
79
|
+
}];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'valdi_tsx/src/JSX';
|
|
2
|
+
import { View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
3
|
+
|
|
4
|
+
export interface CircleViewModel extends View {
|
|
5
|
+
color: string;
|
|
6
|
+
thickness: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Circle(viewModel: CircleViewModel) {
|
|
10
|
+
<custom-view
|
|
11
|
+
iosClass={'SCCCircleView'}
|
|
12
|
+
androidClass={'com.snap.modules.{{MODULE_NAME}}.CircleView'}
|
|
13
|
+
{...viewModel}
|
|
14
|
+
/>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Usage Instructions for This Module
|
|
2
|
+
#
|
|
3
|
+
# Step 1: Add this module to your `BUILD.bazel` file dependencies:
|
|
4
|
+
# `//src/valdi/{{MODULE_NAME}}`
|
|
5
|
+
#
|
|
6
|
+
# Step 2: Import the module in your `.tsx` file:
|
|
7
|
+
# `import { NewModuleComponent } from '{{MODULE_NAME}}/src/NewModuleComponent';`
|
|
8
|
+
#
|
|
9
|
+
# Step 3: Render the component in your `onRender()` function:
|
|
10
|
+
# `<NewModuleComponent title={'Valdi'}/>`
|
|
11
|
+
|
|
12
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
13
|
+
|
|
14
|
+
valdi_module(
|
|
15
|
+
name = "{{MODULE_NAME}}",
|
|
16
|
+
srcs = glob(
|
|
17
|
+
[
|
|
18
|
+
"src/**/*.ts",
|
|
19
|
+
"src/**/*.tsx",
|
|
20
|
+
],
|
|
21
|
+
),
|
|
22
|
+
res = glob([
|
|
23
|
+
"res/**/*.jpeg",
|
|
24
|
+
"res/**/*.jpg",
|
|
25
|
+
"res/**/*.png",
|
|
26
|
+
"res/**/*.svg",
|
|
27
|
+
"res/**/*.webp",
|
|
28
|
+
]),
|
|
29
|
+
visibility = ["//visibility:public"],
|
|
30
|
+
deps = [
|
|
31
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_core",
|
|
32
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_tsx",
|
|
33
|
+
],
|
|
34
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Component } from 'valdi_core/src/Component';
|
|
2
|
+
import { Label, View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
3
|
+
import { systemFont } from 'valdi_core/src/SystemFont';
|
|
4
|
+
import { Style } from 'valdi_core/src/Style';
|
|
5
|
+
|
|
6
|
+
export interface NewModuleViewModel {
|
|
7
|
+
title: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class NewModuleComponent extends Component<NewModuleViewModel> {
|
|
11
|
+
onCreate() {
|
|
12
|
+
// Called when the component is created in the render-tree
|
|
13
|
+
// Used to prepare some resources, precomputed values or subscribe to observables
|
|
14
|
+
}
|
|
15
|
+
onDestroy() {
|
|
16
|
+
// Called the component is not longer in the render-tree
|
|
17
|
+
// Used to dispose of resources and observables
|
|
18
|
+
}
|
|
19
|
+
onViewModelUpdate(previous?: NewModuleViewModel) {
|
|
20
|
+
// Called every time the view model changes
|
|
21
|
+
// Used to trigger some computations, typically used for asynchronous operations,
|
|
22
|
+
// that would then impact the internal component state
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onRender(): void {
|
|
26
|
+
// Called every time the component needs to be rendered
|
|
27
|
+
// Used to define child components and child render-tree
|
|
28
|
+
// Can access "this.viewModel" that contains the current component parameters values
|
|
29
|
+
<view style={styles.root}>
|
|
30
|
+
<label style={styles.label} value={this.viewModel.title} />
|
|
31
|
+
</view>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const styles = {
|
|
36
|
+
root: new Style<View>({
|
|
37
|
+
backgroundColor: 'red',
|
|
38
|
+
width: '100%',
|
|
39
|
+
height: '100%',
|
|
40
|
+
}),
|
|
41
|
+
label: new Style<Label>({
|
|
42
|
+
font: systemFont(20),
|
|
43
|
+
color: 'white',
|
|
44
|
+
}),
|
|
45
|
+
};
|
package/.editorconfig
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
# Unix-style newlines with a newline ending every file
|
|
8
|
+
end_of_line = lf
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
|
|
12
|
+
# 4 spaces for indentation
|
|
13
|
+
indent_size = 4
|
|
14
|
+
indent_style = space
|
|
15
|
+
|
|
16
|
+
# 120 characters max per line
|
|
17
|
+
max_line_length = 120
|
|
18
|
+
|
|
19
|
+
# some files use 2 spaces for indentation
|
|
20
|
+
[*.{json,yml,yaml}]
|
|
21
|
+
indent_size = 2
|
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/**/*.js
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
parserOptions: {
|
|
5
|
+
tsconfigRootDir: __dirname,
|
|
6
|
+
project: ['./tsconfig.json'],
|
|
7
|
+
},
|
|
8
|
+
plugins: ['@typescript-eslint', 'import'],
|
|
9
|
+
extends: [
|
|
10
|
+
'eslint:recommended',
|
|
11
|
+
'plugin:@typescript-eslint/recommended',
|
|
12
|
+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
13
|
+
'plugin:import/recommended',
|
|
14
|
+
'plugin:import/typescript',
|
|
15
|
+
'plugin:unicorn/recommended',
|
|
16
|
+
'prettier',
|
|
17
|
+
],
|
|
18
|
+
rules: {
|
|
19
|
+
eqeqeq: 'error',
|
|
20
|
+
'@typescript-eslint/consistent-type-assertions': [
|
|
21
|
+
'warn',
|
|
22
|
+
{
|
|
23
|
+
assertionStyle: 'as',
|
|
24
|
+
objectLiteralTypeAssertions: 'never',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
28
|
+
'error',
|
|
29
|
+
{
|
|
30
|
+
prefer: 'type-imports',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
'@typescript-eslint/member-ordering': 'warn',
|
|
34
|
+
'@typescript-eslint/no-inferrable-types': ['error', { ignoreParameters: true }],
|
|
35
|
+
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
|
36
|
+
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
|
|
37
|
+
'@typescript-eslint/no-misused-promises': [
|
|
38
|
+
'error',
|
|
39
|
+
{
|
|
40
|
+
checksVoidReturn: false,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
44
|
+
'import/default': 'off',
|
|
45
|
+
'import/namespace': 'off',
|
|
46
|
+
'import/no-unresolved': 'off',
|
|
47
|
+
'import/no-duplicates': 'error',
|
|
48
|
+
'import/no-named-as-default': 'error',
|
|
49
|
+
'import/order': ['warn', { alphabetize: { order: 'asc' } }],
|
|
50
|
+
'unicorn/filename-case': [
|
|
51
|
+
'error',
|
|
52
|
+
{
|
|
53
|
+
cases: {
|
|
54
|
+
camelCase: true,
|
|
55
|
+
pascalCase: true,
|
|
56
|
+
},
|
|
57
|
+
ignore: ['^.*CLI.*'],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
'unicorn/no-array-for-each': 'off',
|
|
61
|
+
'unicorn/no-array-reduce': 'off',
|
|
62
|
+
'unicorn/no-for-loop': 'off',
|
|
63
|
+
'unicorn/no-null': 'off',
|
|
64
|
+
'unicorn/prefer-node-protocol': 'off',
|
|
65
|
+
'unicorn/prefer-query-selector': 'off',
|
|
66
|
+
'unicorn/prefer-ternary': 'off',
|
|
67
|
+
'unicorn/prefer-top-level-await': 'off',
|
|
68
|
+
'unicorn/prefer-spread': 'off',
|
|
69
|
+
'unicorn/prevent-abbreviations': 'off',
|
|
70
|
+
'sort-imports': ['error', { allowSeparatedGroups: true, ignoreDeclarationSort: true }],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# No bzlmod yet
|
|
2
|
+
common --noenable_bzlmod
|
|
3
|
+
|
|
4
|
+
common --bes_instance_name=client
|
|
5
|
+
common --enable_platform_specific_config
|
|
6
|
+
|
|
7
|
+
# Disable workers for repo fetching to prevent OOM
|
|
8
|
+
common --experimental_worker_for_repo_fetching=off
|
|
9
|
+
|
|
10
|
+
# android configuration
|
|
11
|
+
# Expose AndroidResourceInfo provider to Kotlin rules
|
|
12
|
+
common --experimental_google_legacy_api=true
|
|
13
|
+
common --experimental_enable_android_migration_apis=true
|
|
14
|
+
common --incompatible_java_common_parameters=false
|
|
15
|
+
|
|
16
|
+
# Flags for compilation
|
|
17
|
+
common --define enable_web=true
|
|
18
|
+
|
|
19
|
+
build --tool_java_language_version=11
|
|
20
|
+
build --java_language_version=11
|
|
21
|
+
|
|
22
|
+
## Disable sandboxing for macs, both laptops and in CI; the performance hit is much too high.
|
|
23
|
+
build:macos --spawn_strategy=local
|
|
24
|
+
build:linux --sandbox_writable_path=/var/tmp
|
|
25
|
+
|
|
26
|
+
# common cc configuration
|
|
27
|
+
build --cxxopt=-std=c++20
|
|
28
|
+
build --cxxopt=-Wno-ambiguous-reversed-operator
|
|
29
|
+
build --cxxopt=-D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
|
|
30
|
+
build --host_cxxopt=-std=c++20
|
|
31
|
+
|
|
32
|
+
## we need to disable this due to a bug in bazel
|
|
33
|
+
## see https://github.com/bazelbuild/bazel/issues/12381
|
|
34
|
+
build --incompatible_use_specific_tool_files=false
|
|
35
|
+
build --incompatible_enable_cc_toolchain_resolution
|
|
36
|
+
|
|
37
|
+
# iOS and Apple cc changes and hacks
|
|
38
|
+
## For Objective-C source files
|
|
39
|
+
build --per_file_copt=.*\.mm\$@-std=c++20
|
|
40
|
+
build --host_per_file_copt=.*\.mm\$@-std=c++20
|
|
41
|
+
build --ios_minimum_os=12.0
|
|
42
|
+
|
|
43
|
+
## TODO: (dchapp) this is currently needed otherwise -O0 and -DDEBUG=1 get passed to compilations of .mm/.m for production flavor builds
|
|
44
|
+
build --experimental_objc_fastbuild_options=""
|
|
45
|
+
## HACK inject this in the default toolchain which is only used on macos until we switch to bazel_toolchains
|
|
46
|
+
build:macos --copt=-fvisibility=hidden
|
|
47
|
+
|
|
48
|
+
# java configuration
|
|
49
|
+
## Disable some java checks for now, djinni generates code that errors out
|
|
50
|
+
build --javacopt=-XepDisableAllChecks
|
|
51
|
+
build --java_runtime_version=11
|
|
52
|
+
build --tool_java_runtime_version=17
|
|
53
|
+
|
|
54
|
+
build --flag_alias=snap_flavor=@snap_platforms//flavors:snap_flavor
|
|
55
|
+
build --snap_flavor=platform_development
|
|
56
|
+
|
|
57
|
+
build --android_crosstool_top=@androidndk//:toolchain
|
|
58
|
+
build --define=android_dexmerger_tool=d8_dexmerger
|
|
59
|
+
build --define=android_incremental_dexing_tool=d8_dexbuilder
|
|
60
|
+
build --define=android_standalone_dexing_tool=d8_compat_dx
|
|
61
|
+
build --incremental_dexing
|
|
62
|
+
|
|
63
|
+
# Disable 3rd party libs warnings
|
|
64
|
+
build --per_file_copt=external/com_github_grpc_grpc/.*\$@-Wno-everything
|
|
65
|
+
build --per_file_copt=external/snap_protobuf/.*\$@-Wno-everything
|
|
66
|
+
build --per_file_copt=external/boringssl/.*\$@-Wno-everything
|
|
67
|
+
build --per_file_copt=external/com_github_google_flatbuffers/.*\$@-Wno-everything
|
|
68
|
+
|
|
69
|
+
# Enable persistent worker for Valdi compilation
|
|
70
|
+
build --strategy=ValdiCompile=worker
|
|
71
|
+
|
|
72
|
+
## Disable sandboxing for macs, both laptops and in CI; the performance hit is much too high.
|
|
73
|
+
build:macos --spawn_strategy=local
|
|
74
|
+
build:linux --sandbox_writable_path=/var/tmp
|
|
75
|
+
|
|
76
|
+
# Disable disk cache to save disk space
|
|
77
|
+
# https://docs.google.com/document/d/1N8W_M83n9jhMi7pgUhXuEuxypb3dmlHBu_CG_eXipXI/edit?usp=sharing
|
|
78
|
+
build --disk_cache=""
|
|
79
|
+
|
|
80
|
+
# common build configuration
|
|
81
|
+
build --experimental_generate_json_trace_profile
|
|
82
|
+
# enable grpc log
|
|
83
|
+
build --remote_grpc_log=/tmp/snap_client_grpc.log
|
|
84
|
+
build --experimental_reuse_sandbox_directories
|
|
85
|
+
|
|
86
|
+
# Default JS engine
|
|
87
|
+
build --flag_alias=valdi_js_engine=@valdi//bzl/valdi:js_engine
|
|
88
|
+
build --valdi_js_engine=hermes
|
|
89
|
+
|
|
90
|
+
# Valdi Open Source Flags
|
|
91
|
+
build --define=open_source_build=true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
7.2.1
|