Solvedlottie ios Use image resources in lottie-ios

Hi, I read your code in the 'LOTLayerView.m' file, there is a method called '- (void)_setImageForAsset' to load image resources in our app used in lottie animation. But in the method you use '+ (nullable UIImage *)imageNamed:(NSString *)name;' to load image, which means we can only load images in app's main bundle. Is there any way for us to load images in other bundle, or is it possible for us to load images from a specified directory, for example, the cache directory or the document directory. Looking forward to your reply.

18 Answers

✔️Accepted Answer

Hi guys,

I think the best solution is AnimationImageProvider. Lottie has AnimationImageProvider. I am sharing sample code below.

    public init(with jsonName: String) {
        super.init(frame: .zero)
        let animation = Animation.named(jsonName, bundle: getBundle())
        let imageProvider = BundleImageProvider(bundle: getBundle(), searchPath: nil)
        animationView = AnimationView(animation: animation, imageProvider: imageProvider)

Take care of yourself 🤘🏻

Other Answers:

This issue is fixed in current version. Thanks a lot!!!
First keep in mind that the file directory is the same as the JSON file ruled. There is a key to describe this image file folder name: "u":"images/" So your resource file directory must be like this
Then you can use this method to load you JSON file and lottie will search the images in the same folder automatically,
LOTAnimationView* lottieAnimation = [LOTAnimationView animationWithFilePath:YourFilePath];

Related Issues:

lottie ios animation stop after enter background
Seem we have this to pause in background and restart when it reach foreground animationView.backgrou...
lottie ios Use image resources in lottie-ios
Hi guys I think the best solution is AnimationImageProvider Lottie has AnimationImageProvider I am s...
ant motion 模版代码下载下来导入到dva搭建的项目里面,启动时报错(npm start)
开启 JavaScript 就可以了 你好,我下载的Home项目引入到项目工程里面,为了方便,我全部放到了components下面,引入和基本流程没有问题。在家里的win10上面启动没有报错,在win...
react native modal The statusbar turns white when the modal is open (only on certain devices)
statusBarTranslucent property has been added to Modal of RN 0.62 I think this problem has been solve...
react native circular progress No component found for view with name "ARTSurfaceView"
I drag and dropped node_modules/react-native/Libraries/ART/ART.xcodeproj somewhere to my Xcode proje...
react native reanimated V2: Upgrade error InnerNativeModule.installCoreFunctions
was facing same problem react-native: 0.66.0 react-native-reanimated: ^2.3.0-beta.2 ...
uCrop FileUtils NumberFormatException
This is not a complete solution just nothing will happen But I think users should be able to open fi...
react native modal Error property 'left' is not supported by native animated module when using swipe
This is not due to react native limitations Keeping it as simple as the above ...
react native reanimated RN 0.61 Android build fails
I am still facing this This likely has to do with AndroidX or other things of which I am somewhat ig...
react native circular progress Invariant Violation: requireNative Component: "RNSVGPath" was not found in the UIManager
for any future person coming here with this issue that I faced on Android make sure to recompile you...
moviepy ImageMagick not detected by moviepy while using SubtitlesClip
comment out (or remove the line that reads) <policy domain=path rights=none pattern=@* /> <!-- <poli...
react native modal Tap outside to close
@Doko-Demo-Doa according to the source code haven't implemented yet there is no close event on backd...
react native modal How to avoid keyboard for bottom half modal
FWIW for those coming from Google Let's say we have a bottom half modal with some TextInput ...
react native reanimated TurboModuleRegistry NativeReanimated error
When loading with 2.0.0-alpha.8 I'm still running into ExceptionsManager.js:179 Invariant Violation:...
manim Failed to build pycairo in ubuntu
I got the same problem during the installation and these commands solved the problem. ...
moviepy Unable to run the sample code! Getting errors. Plase Help
I just figured this out. imagemagick (ie convert) has a policy.xml file that stops you from accessin...
react native modal How could we add swipe down to close function?
+1 for this feature please Hi I love the way this module:
react native reanimated [Jest] V2 - rc2 Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeReanimated'
I opened a PR but if you guys want a temporary fix Use ds300/patch-package and put this on patches/r...
react native reanimated Unable to resolve module ./abs
@jakub-gonet I think in my case watchman was the culprit as even after --reset-cache the issue was s...
barba Update body class?
Got it working with events too: Is it possible to update the body class between transitions? ...
react native reanimated [RN 0.66] iOS build failure: 'boost/operators.hpp' file not found
Try react-native-reanimated: 2.3.0-beta.2 It has fix for search paths Description After updating to ...
react native modal error: bundling failed: Error: Unable to resolve module `./animations`
this command fixed my issue npm start -- --reset-cache I upgraded my react-native-modal from 7.0.2 t...
react native reanimated Android only -> E/ReactNativeJS: undefined is not an object (evaluating '_ReanimatedModule.default.configureProps')
Make sure that you've added new ReanimatedPackage(),in under getPackages Import...
moviepy AttributeError: module '' has no attribute 'audio_fadein'
For everyone that has the same issue i solved it by modifying the selected init file shown in the pi...
lottie android JSON Reader AssertionError when doInBackground (Android 7, 8)
We are having the same issues (Lottie 2.5.5) - only Android 8 So hope to find a fix soon ...
SkeletonView Wrong skeleton view width on iPhone 8 plus
Ok I've found my problem I was calling showSkeleton in viewDidLoad Moving it to viewDidAppear fixed ...
aseprite Skia build fails on Mojave
For me I have to use @adennen 's solution and also disable webp via skia_use_libwebp=false due to I ...
animated tab bar Major issue when using hidesBottomBarWhenPushed. Please investigate
@sentiasa Hi! It's very easy to solve this issue by using this: Hey guys ...
barba CF7 Wordpess reload
Hi The newest version of wpcf7 needs some code changes: Hi there ...
react native modal modal not begin from bottom
<Modal style={{ margin: 0 }}>....</Modal> can fix your problem I try to make modal that begin from b...
CompactCalendarView Show Event indicators to currently selected day
I've released a new beta version: Let me know if you have any feedback While Adding events to curren...
barba View afterEnter hook on browser refresh is not triggered
Fixed in @barba/core 2.3.15 Hi there! First of all thanks alot for the great work Using barba since ...
react three fiber Panning / Orbit Controls
@gino8080 you can also import OrbitalControl from drei I'm trying to implement a panning system on s...
svg.js svg rectangle with select resize and draggy
Oh cmon - you enable pointerevents on purpose for all elements with and then you wonder why the rect...
CompactCalendarView Remove First Day as SelectedDayBgColor
Added new xml property and method: Set that to false to not select first day of month Released anew ...
barba Uncaught (in promise) Error: xhr: HTTP code is not 200
I may have had some luck with this issue by passing a larger value to the XHR Timeout The default is...
SkeletonView SkeletonView not working in TableViewCell with custom class
@pennywise94 I ran into this issue too; the giant solid happens because calling showSkeleton() on a ...
FluidTransitions willBlur, didBlur listener not call
Experiencing this again with react-navigation@3.1.0 Perhaps an issue in react-navigation See this th...
react three fiber ✍️ Roadmap for 2.x (suggestions welcome)
@samburgers with the last commits that went in you can do this easily Just keep configs in state and...
lottie react native Could not find
you are right there is also something else your other build.gradle file add maven url 'https://maven...
lottie react native 'Lottie/Lottie.h' file not found on release builds
@dejakob Go to General > Embedded Binaries > add Lottie.framework Dear I added lottie-react-native i...
lottie react native iOS doesn't build latest version 3.0.3
I've solved this issue If you're using ios/{projectName}.xcodeproj with XCode to build your project ...
lottie react native Error in Latest versions (3.1.8)
That's what worked for me. Description [!] CocoaPods could not find compatible versions for pod lott...
lottie react native Linking lottie-ios crashes on iOS
@rodrigoelp I've got it compiling in Xcode 10 (RN 0.57) by linking everything manually: Remove lotti...
lottie react native Build failed after update
In app/build.gradle add this 👍 Works fine After update to 2.5.0 version (from 2.3.2) build is faili...
lottie react native Execution failed for task ':lottie-react-native:compileDebugJavaWithJavac'.
Migrating to Android X Fixed it for me i.e: Adding to my and running Jetifier ...
lottie react native Cannot build on React Native 0.41.2
I got it working by adding Lottie.framework to Embedded Binaries in XCode. Current behavior: Cannot ...
lottie react native 2.3.0 Animations no longer appear (upgrading from 1.2 to 2.3)
I ran into this problem as well after upgrading from version 2.2.7 to 2.3.1 all my animations in iOS...
lottie react native remote uri
Hi Again We have fixed the problem with this approach : and the component : I tried using along the ...
lottie react native Create androidx support
This comes down to updating the dependencies to a version of lottie-android of at least 2.8.0 ...