Skip to content

feat: add loggger #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2024
Merged
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
8 changes: 3 additions & 5 deletions harmony/clip_path/src/main/ets/ClipPath.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RNComponentContext, RNViewBase, DescriptorWrapper, RNComponentFactory,
import {CustomComponentBuilder} from '@rnoh/react-native-openharmony/src/main/ets/RNOH'
// import codegen 生成的内容
import { RNC } from "@rnoh/react-native-openharmony/generated";
import Logger from "./Logger";


import { TViewBox, IViewPort, TChildrenBuilder } from './types'
Expand Down Expand Up @@ -57,6 +58,7 @@ export struct ClipPath {
@State propertyArr: Array<string> = [];

aboutToAppear() {
Logger.info(`${ClipPath.NAME}: aboutToAppear.`);
this.eventEmitter = new RNC.ClipPath.EventEmitter(this.ctx.rnInstance, this.tag)
this.onDescriptorWrapperChange(this.ctx.descriptorRegistry.findDescriptorWrapperByTag<RNC.ClipPath.DescriptorWrapper>(this.tag)!)
this.cleanUpCallbacks.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
Expand All @@ -66,10 +68,7 @@ export struct ClipPath {
))

const props = this.descriptorWrapper.props
console.log(`FG 1.1 ${JSON.stringify(props)}`)
this.propertyArr = Object.entries(props).map((item: Array<string>) => `${item[0]}: ${item[1]}`)
console.log(`FG 2 ${this.propertyArr}`)
console.log(`FG 3 ${JSON.stringify(this.descriptorWrapper)}`)
}

private onDescriptorWrapperChange(descriptorWrapper: RNC.ClipPath.DescriptorWrapper) {
Expand All @@ -78,6 +77,7 @@ export struct ClipPath {
}

aboutToDisappear() {
Logger.info(`${ClipPath.NAME}: aboutToDisappear.`);
this.cleanUpCallbacks.forEach(cb => cb())
}

Expand Down Expand Up @@ -220,7 +220,6 @@ export struct ClipPath {
if (rotO === 0 && rotOy === 0) {
val.centerY = scaleConfig.centerY;
}
console.log(`FG rotate ${JSON.stringify(val)}`)
return val
}

Expand Down Expand Up @@ -264,7 +263,6 @@ export struct ClipPath {
}
}

console.log(`FG scale ${JSON.stringify(val)}`)
return val
}

Expand Down
131 changes: 23 additions & 108 deletions harmony/clip_path/src/main/ets/ClipPathCode.ets
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { TViewBox, IViewPort, TChildrenBuilder } from './types'
import ListPanel from './ListPanel'

Expand Down Expand Up @@ -71,32 +70,8 @@ export struct ClipPathCode {
@Prop scOx: number = 0;
@Prop scOy: number = 0;
@Prop scPercentageValue: boolean = false;


// ctx!: RNOHContext
// tag: number = 0
// @State descriptor: ClipPathDescriptor = {} as ClipPathDescriptor
// @BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
@BuilderParam childrenBuilder: TChildrenBuilder = this.defaultChildrenBuilder
// private unregisterDescriptorChangesListener?: () => void = undefined
@State propertyArr: Array<string> = [];

// aboutToAppear() {
// this.descriptor = this.ctx.descriptorRegistry.getDescriptor<ClipPathDescriptor>(this.tag)
// this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
// (newDescriptor) => {
// this.descriptor = (newDescriptor as ClipPathDescriptor)
// }
// )
// console.log(`FG ${JSON.stringify(this)}`)
// this.propertyArr = Object.entries(this).map((item: Array<string>) => `${item[0]}: ${item[1]}`)
// console.log(`FG ${this.propertyArr}`)
// console.log(`FG ${JSON.stringify(this.descriptor)}`)
// }

// aboutToDisappear() {
// this.unregisterDescriptorChangesListener?.()
// }
@State propertyArr: Array<string> = [];

computedShapeWidth(): string {
const viewBox = this.computedViewBoxParam()
Expand All @@ -111,18 +86,14 @@ export struct ClipPathCode {
computedClipParams(): PathAttribute | boolean {
const openClip = this.openClip
const d = this.d
// const viewBox = this.computedViewBoxParam()
return openClip ? new Path({ commands: d }) : false
}

computedViewBoxParam(): IViewPort {
const viewBox = this.viewBox
if (viewBox?.length !== 4) return {}
// return {
// x: viewBox[0],
// y: viewBox[1],
// width: viewBox[2],
// height: viewBox[3]
// }
if (viewBox?.length !== 4) {
return {}
}
return {
x: viewBox[0] + 'px',
y: viewBox[1] + 'px',
Expand Down Expand Up @@ -158,18 +129,30 @@ export struct ClipPathCode {

computedStrokeCap(): LineCapStyle {
let strokeCap = this.strokeCap || 'butt'
if(String(strokeCap).toLowerCase() === "butt") return LineCapStyle.Butt
if(String(strokeCap).toLowerCase() === "round") return LineCapStyle.Round
if(String(strokeCap).toLowerCase() === "square") return LineCapStyle.Square
if (String(strokeCap).toLowerCase() === "butt") {
return LineCapStyle.Butt
}
if (String(strokeCap).toLowerCase() === "round") {
return LineCapStyle.Round
}
if (String(strokeCap).toLowerCase() === "square") {
return LineCapStyle.Square
}
return LineCapStyle.Butt
}

computedStrokeJoin(): LineJoinStyle {
let strokeJoin = this.strokeJoin || 'miter'
// bevel/miter/round
if(String(strokeJoin).toLowerCase() === "miter") return LineJoinStyle.Miter
if(String(strokeJoin).toLowerCase() === "round") return LineJoinStyle.Round
if(String(strokeJoin).toLowerCase() === "bevel") return LineJoinStyle.Bevel
if (String(strokeJoin).toLowerCase() === "miter") {
return LineJoinStyle.Miter
}
if (String(strokeJoin).toLowerCase() === "round") {
return LineJoinStyle.Round
}
if (String(strokeJoin).toLowerCase() === "bevel") {
return LineJoinStyle.Bevel
}
return LineJoinStyle.Miter
}

Expand All @@ -182,11 +165,6 @@ export struct ClipPathCode {
const transX = this.transX || 0
const transY = this.transY || 0
const transPercentageValue = this.transPercentageValue || false
// let val: TranslateOptions = {
// x: transX || 0,
// y: transY || 0,
// z: 0
// }
let val: TranslateOptions = {
x: `${transX}px`,
y: `${transY}px`,
Expand All @@ -211,13 +189,6 @@ export struct ClipPathCode {
centerY: rotO
} as RotateOptions

// if(rotOx || (rotOx === 0)){
// val.centerX = rotOx || 0
// }
// if(rotOy || (rotOy === 0)){
// val.centerY = rotOy || 0
// }

if (rotOx) {
val.centerX = `${rotOx}px`
}
Expand All @@ -244,7 +215,6 @@ export struct ClipPathCode {
if (rotO === 0 && rotOy === 0) {
val.centerY = scaleConfig.centerY;
}
console.log(`FG rotate ${JSON.stringify(val)}`)
return val
}

Expand All @@ -264,13 +234,6 @@ export struct ClipPathCode {
centerY: `${scO}px`
} as RotateOptions

// if(scOx || (scOx === 0)){
// val.centerX = scOx || 0
// }
// if(scOy || (scOy === 0)){
// val.centerY = scOy || 0
// }

if (scX !== 1) {
val.x = scX
}
Expand All @@ -295,53 +258,14 @@ export struct ClipPathCode {
}
}

console.log(`FG scale ${JSON.stringify(val)}`)
return val
}

@Builder
defaultChildrenBuilder() {
};

// build() {
// Column() {
// if (this.showProperty) {
// ListPanel({
// arr: this.propertyArr
// })
// }
// Shape() {
// Path({
// commands: this.d
// })
// Column() {
// this.childrenBuilder()
// ForEach(this.descriptor.childrenTags, (tag: Tag) => {
// Column() {
// RNComponentFactory({ ctx: this.ctx, tag: tag, buildCustomComponent: this.buildCustomComponent })
// }
// }, (tag: Tag) => tag.toString())
// }
// .alignItems(HorizontalAlign.Start)
// }
// .key(this.computedKey())
// .viewPort(this.computedViewBoxParam())
// .fill(this.computedFill())
// .stroke(this.computedStroke())
// .strokeWidth(this.computedStrokeWidth())
// .strokeMiterLimit(this.computedStrokeMiter())
// .strokeLineCap(this.computedStrokeCap())
// .strokeLineJoin(this.computedStrokeJoin())
// .zIndex(this.computedTranslateZ())
// .translate(this.computedTranslateValue())
// .scale(this.computedScaleValue())
// .rotate(this.computedRotateValue())
// .clip(this.computedClipParams())
// }
// }

build() {
// RNViewBase({ ctx: this.ctx, tag: this.tag }) {
Column() {
if (this.showProperty) {
ListPanel({
Expand All @@ -354,20 +278,11 @@ export struct ClipPathCode {
})
Column() {
this.childrenBuilder()
// ForEach(this.descriptor.childrenTags, (tag: Tag) => {
// Column() {
// RNComponentFactory({ ctx: this.ctx, tag: tag, buildCustomComponent: this.buildCustomComponent })
// }
// }, (tag: Tag) => tag.toString())
}
.alignItems(HorizontalAlign.Start)
// .width('100%')
// .height('100%')
// .clip(true)
}
.width(this.computedShapeWidth())
.height(this.computedShapeHeight())
// .backgroundColor(Color.Pink)
.key(this.computedKey())
.viewPort(this.computedViewBoxParam())
.fill(this.computedFill())
Expand Down
9 changes: 0 additions & 9 deletions harmony/clip_path/src/main/ets/ClipPathPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,3 @@ export class ClipPathPackage extends RNPackage {
}
}
}


// 根 ts.ts
export * from "./src/main/ets/ClipPathPackage";

// 根 index.ts
export * from "./ts";
export * from './src/main/ets/ClipPath'

60 changes: 60 additions & 0 deletions harmony/clip_path/src/main/ets/Logger.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import hilog from '@ohos.hilog';
class Logger
{
private domain : number;
private prefix : string;
private format : string = '%{public}s, %{public}s';
private isDebug : boolean;
/**
* constructor.
* @param Prefix Identifies the log tag.
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
* */
constructor(prefix
: string = 'MyApp', domain
: number = 0xFF00, isDebug = false)
{
this.prefix = prefix;
this.domain = domain;
this.isDebug = isDebug;
}
debug(... args
: string[]) : void
{
if (this.isDebug)
{
hilog.debug(this.domain, this.prefix, this.format, args);
}
}
info(... args
: string[]) : void { hilog.info(this.domain, this.prefix, this.format, args); }
warn(... args
: string[]) : void { hilog.warn(this.domain, this.prefix, this.format, args); }
error(... args
: string[]) : void { hilog.error(this.domain, this.prefix, this.format, args); }
}
export default new Logger('HarmonyPicker', 0xFF00, true)