🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

@ohmi/oh-lottie-react-native

Package Overview
Dependencies
Maintainers
7
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ohmi/oh-lottie-react-native

c-api-foundation

latest
npmnpm
Version
6.4.1-0.1.20
Version published
Maintainers
7
Created
Source

模板版本:v0.2.2

ohmi/oh-lottie-react-native

Supported platforms License

本项目基于 react-native-oh-library/lottie-react-native 开发。

[!TIP] Gitee 地址

安装与使用

请到三方库的 Releases 发布地址查看配套的版本信息:@ohmi/oh-lottie-react-native Releases 。对于未发布到npm的旧版本,请参考安装指南安装tgz包。

进入到工程目录并输入以下命令:

npm

npm install @ohmi/oh-lottie-react-native

yarn

yarn add @ohmi/oh-lottie-react-native

下面的代码展示了这个库的基本使用场景:

[!WARNING] 使用时 import 的库名不变。

[!TIP] 以下 demo 中使用的是本地文件。

import React from "react";
import { View } from "react-native";
import LottieView from "lottie-react-native";

const App = () => {
  return (
    <View style={{ flex: 1 }}>
      <LottieView 
        style={{ width: 300, height: 300 }} 
        source={require("./assets/xxx.json")}   
        autoPlay 
        loop />
    </View>
  );
};

export default App;

目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。

首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 harmony

1.在工程根目录的 oh-package.json5 添加 overrides 字段

{
  ...
  "overrides": {
    "@rnoh/react-native-openharmony" : "./react_native_openharmony"
  }
}

2.引入原生端代码

目前有两种方法:

  • 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
  • 直接链接源码。

方法一:通过 har 包引入(推荐)

[!TIP] har 包位于三方库安装路径的 harmony 文件夹下。

打开 entry/oh-package.json5,添加以下依赖

"dependencies": {@ohmi/oh-lottie-react-native
    "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
    "@ohmi/oh-lottie-react-native": "file:../../node_modules/@ohmi/oh-lottie-react-native/harmony/lottie.har"
  }

点击右上角的 sync 按钮

或者在终端执行:

cd entry
ohpm install

方法二:直接链接源码

[!TIP] 如需使用直接链接源码,请参考直接链接源码说明

3.配置 CMakeLists 和引入 LottieAnimationViewPackage

打开 entry/src/main/cpp/CMakeLists.txt,添加:

project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)

add_subdirectory("${RNOH_CPP_DIR}" ./rn)

# RNOH_BEGIN: manual_package_linking_1
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
+ add_subdirectory("${OH_MODULES}/@ohmi/oh-lottie-react-native/src/main/cpp" ./lottie)
# RNOH_END: manual_package_linking_1

file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")

add_library(rnoh_app SHARED
    ${GENERATED_CPP_FILES}
    "./PackageProvider.cpp"
    "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)
target_link_libraries(rnoh_app PUBLIC rnoh)

# RNOH_BEGIN: manual_package_linking_2
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
+ target_link_libraries(rnoh_app PUBLIC rnoh_lottie)
# RNOH_END: manual_package_linking_2

打开 entry/src/main/cpp/PackageProvider.cpp,添加:

#include "RNOH/PackageProvider.h"
#include "SamplePackage.h"
+ #include "LottieAnimationViewPackage.h"

using namespace rnoh;

std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
    return {
      std::make_shared<SamplePackage>(ctx),
+     std::make_shared<LottieAnimationViewPackage>(ctx)
    };
}

打开 entry/src/main/ets/RNPackagesFactory.ts,添加:

[!TIP] 版本 6.4.1-0.1.13 及以上需要

  ...
+ import {LottieAnimationViewPackage} from '@ohmi/oh-lottie-react-native/ts';

export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
  return [
+    new LottieAnimationViewPackage(ctx)
  ];
}

4.在 ArkTs 侧引入 Lottie 组件

找到 function buildCustomComponent(),一般位于 entry/src/main/ets/pages/index.etsentry/src/main/ets/rn/LoadBundle.ets,添加:

  ...
+ import { LottieAnimationView, LOTTIE_TYPE } from "@ohmi/oh-lottie-react-native"

@Builder
export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
  ...
+ if (ctx.componentName === LOTTIE_TYPE) {
+   LottieAnimationView({
+     ctx: ctx.rnComponentContext,
+     tag: ctx.tag
+   })
+ }
 ...
}

[!TIP] 本库使用了混合方案,需要添加组件名。

entry/src/main/ets/pages/index.etsentry/src/main/ets/rn/LoadBundle.ets 找到常量 arkTsComponentNames 在其数组里添加组件名

const arkTsComponentNames: Array<string> = [
  SampleView.NAME,
  GeneratedSampleView.NAME,
  PropsDisplayer.NAME,
+ LOTTIE_TYPE
  ];

5.运行

点击右上角的 sync 按钮

或者在终端执行:

cd entry
ohpm install

然后编译、运行即可。

约束与限制

兼容性

要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。

请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:@ohmi/oh-lottie-react-native Releases

权限要求

  • 如果 source 使用网络 url 应用需要申请网络权限

    entry/src/main/module.json5中添加

requestPermissions: [
  {
    name: "ohos.permission.INTERNET",
  },
],
  • 如果使用的 json 文件里有依赖图片资源或使用 imageAssetsFolder 属性,需要将资源文件放置到 HarmonyOS 工程 rawfile 下对应的路径中

rawfile 路径:entry/src/main/resources/rawfile

属性

[!TIP] "Platform"列表示该属性在原三方库上支持的平台。

[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

NameDescriptionTypeDefaultRequiredPlatformHarmonyOS Support
sourceMandatory - The source of animation. Can be referenced as a local asset by a string, or remotely with an object with a uri property, or it can be an actual JS object of an animation, obtained (for example) with something like require('../path/to/animation.json')string| AnimationObject | { uri: string }NoneYesAllYes
progressA number between 0 and 1. This number represents the normalized progress of the animation. If you update this prop, the animation will correspondingly update to the frame at that progress value. This prop is not required if you are using the imperative API.number0NoiOS, Android, WindowsYes
speedThe speed the animation will progress. Sending a negative value will reverse the animationnumber1NoAllYes
durationThe duration of the animation in ms. Takes precedence over speed when set. This only works when source is an actual JS object of an animation.numberundefinedNoiOS, Android, WindowsYes
loopA boolean flag indicating whether or not the animation should loop.booleantrueNoAllYes
autoPlayA boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API.booleanfalseNoAllYes
resizeModeDetermines how to resize the animated view when the frame doesn't match the raw image dimensions. Supports cover, contain and center.'cover'| 'contain' | 'center'containNoiOS, Android, WindowsYes
styleStyle attributes for the view, as expected in a standard View, aside from border stylingStylePropNoneNoiOS, Android, WindowsYes
webStyleStyle attributes for the view, it uses CSSProperties.CSSPropertiesNoneNoWebNo
imageAssetsFolderNeeded for Android and HarmonyOS to work properly with assets, iOS will ignore it.stringNoneNoAndroidYes
useNativeLoopingOnly Windows. When enabled, uses platform-level looping to improve smoothness, but onAnimationLoop will not fire and changing the loop prop will reset playback rather than finishing gracefully.booleanfalseNoWindowsNo
onAnimationLoopOnly Windows and Web. A callback function invoked when the animation loops.callbackNoneNoWindows, WebNo
onAnimationFinishA callback function which will be called when animation is finished. This callback is called with a boolean isCancelled argument, indicating if the animation actually completed playing, or if it was cancelled, for instance by calling play() or reset() while is was still playing. Note that this callback will be called only when loop is set to false.callbackNoneNoAllYes
onAnimationFailureA callback function which will be called if an error occurs while working with the animation (loading, running, etc). This callback is called with a string error argument, which contains the error message that occured.callbackNoneNoAllYes
onAnimationLoadedA callback function which will be called when animation is done loading. This callback is called with no parameters.callbackNoneNoAllYes
renderModea String flag to set whether or not to render with HARDWARE or SOFTWARE acceleration'AUTOMATIC'| 'HARDWARE' | 'SOFTWARE'AUTOMATICNoiOS, AndroidNo
cacheCompositionOnly Android and HarmonyOS, a boolean flag indicating whether or not the animation should do caching.booleantrueNoAndroidYes
colorFiltersAn array of objects denoting layers by KeyPath and a new color filter value (as hex string).Array[]NoiOS, Android, WindowsYes
textFiltersAndroidOnly Android, an array of objects denoting text values to find and replace.Array[]NoAndroidNo
textFiltersIOSOnly iOS, an array of objects denoting text layers by KeyPath and a new string value.Array[]NoiOSNo
hoverOnly Web, a boolean denoting whether to play on mouse hover.booleanfalseNoWebNo
directionOnly Web a number from 1 or -1 denoting playing direction.1| -11NoWebNo

静态方法 (Imperative API)

[!TIP] "Platform"列表示该属性在原三方库上支持的平台。

[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

NameDescriptionTypeRequiredPlatformHarmonyOS Support
playPlay the animation all the way through, at the speed specified as a prop. It can also play a section of the animation (not available on web) when called as play(startFrame, endFrame).functionNoAllYes
resetReset the animation back to 0 progress.functionNoAllYes
pausePauses the animation.functionNoAllYes
resumeResumes the paused animation.functionNoAllYes

遗留问题

  • 原库部分接口在 HarmonyOS 中没有对应属性及接口处理相关逻辑,问题: issue#18

其他

开源协议

本项目基于 Apache License 2.0 ,请自由地享受和参与开源。

Keywords

lottie

FAQs

Package last updated on 08 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts