mirror of
https://github.com/rive-app/rive-ios.git
synced 2026-01-18 17:11:28 +01:00
few bits to sort out - [x] make our mix of simulator/emulator consistent, settling on emulator - [x] passing the factory in works great for just in time asset decoding, but its not amazing when you want to decode ahead of time. - [x] couple of places left to pass this function signature through. (Question) is there a neater way to get this done, feels a bit like we are going back to parameter explosion a bit? - [x] should do a few examples, i think the complexity grows quite a bit in this one as you add caching, or callbacks - [x] should get the cached images/fonts to draw on init as well, either warming up cache, or jitting - [x] examples loading assets from the bundle (also there seem to be actual asset things too? should we use those?!) - [x] add test - [x] re-add "preview" project & rev the preview project once this has been deployed. (do this after new ios deploy) - [x] fix up race condition (see comment) https://github.com/rive-app/rive/assets/1216025/2c14330f-e8a4-481b-bc27-4807cabe3b82 (simple example, both swift ui and standard)  Diffs= fabb7f97f Ios out of band (#6232) Co-authored-by: Gordon Hayes <pggordonhayes@gmail.com> Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
96 lines
1.8 KiB
Plaintext
96 lines
1.8 KiB
Plaintext
//
|
|
// RiveFactory.m
|
|
// RiveRuntime
|
|
//
|
|
// Created by Maxwell Talbot on 08/11/2023.
|
|
// Copyright © 2023 Rive. All rights reserved.
|
|
//
|
|
|
|
#import <Rive.h>
|
|
#import <RivePrivateHeaders.h>
|
|
#import <RiveFactory.h>
|
|
|
|
@implementation RiveFont
|
|
{
|
|
rive::rcp<rive::Font> instance; // note: we do NOT own this, so don't delete it
|
|
}
|
|
- (instancetype)initWithFont:(rive::rcp<rive::Font>)font
|
|
{
|
|
if (self = [super init])
|
|
{
|
|
instance = font;
|
|
return self;
|
|
}
|
|
else
|
|
{
|
|
return nil;
|
|
}
|
|
}
|
|
- (rive::rcp<rive::Font>)instance
|
|
{
|
|
return instance;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation RiveRenderImage
|
|
{
|
|
rive::rcp<rive::RenderImage> instance; // note: we do NOT own this, so don't delete it
|
|
}
|
|
- (instancetype)initWithImage:(rive::rcp<rive::RenderImage>)image
|
|
{
|
|
if (self = [super init])
|
|
{
|
|
instance = image;
|
|
return self;
|
|
}
|
|
else
|
|
{
|
|
return nil;
|
|
}
|
|
}
|
|
- (rive::rcp<rive::RenderImage>)instance
|
|
{
|
|
return instance;
|
|
}
|
|
|
|
@end
|
|
|
|
/*
|
|
* RiveFactory
|
|
*/
|
|
@implementation RiveFactory
|
|
{
|
|
rive::Factory* instance; // note: we do NOT own this, so don't delete it
|
|
}
|
|
|
|
// Creates a new RiveFactory from a cpp RiveFactory
|
|
- (instancetype)initWithFactory:(rive::Factory*)factory
|
|
{
|
|
if (self = [super init])
|
|
{
|
|
instance = factory;
|
|
return self;
|
|
}
|
|
else
|
|
{
|
|
return nil;
|
|
}
|
|
}
|
|
|
|
- (RiveRenderImage*)decodeImage:(nonnull NSData*)data
|
|
{
|
|
UInt8* bytes = (UInt8*)[data bytes];
|
|
return [[RiveRenderImage alloc]
|
|
initWithImage:instance->decodeImage(rive::Span<const uint8_t>(bytes, [data length]))];
|
|
}
|
|
|
|
- (RiveFont*)decodeFont:(nonnull NSData*)data
|
|
{
|
|
UInt8* bytes = (UInt8*)[data bytes];
|
|
return [[RiveFont alloc]
|
|
initWithFont:instance->decodeFont(rive::Span<const uint8_t>(bytes, [data length]))];
|
|
}
|
|
|
|
@end
|