Skip to content

Commit 43a6183

Browse files
committed
feat(ios): add databinding error handling
1 parent e4b4fe3 commit 43a6183

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

example/app/(examples)/DataBinding.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from 'react-native';
99
import Rive, {
1010
AutoBind,
11-
BindByIndex,
12-
BindByName,
13-
BindEmpty,
11+
// BindByIndex,
12+
// BindByName,
13+
// BindEmpty,
1414
Fit,
1515
RNRiveError,
1616
RNRiveErrorType,

ios/RNRiveError.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct RNRiveError {
1414
static let IncorrectStateMachineName = BaseRNRiveError(type: "IncorrectStateMachineName")
1515
static let IncorrectStateMachineInput = BaseRNRiveError(type: "IncorrectStateMachineInput")
1616
static let TextRunNotFoundError = BaseRNRiveError(type: "TextRunNotFoundError")
17+
static let DataBindingError = BaseRNRiveError(type: "DataBindingError")
1718

1819

1920
static func mapToRNRiveError(riveError: NSError) -> BaseRNRiveError? {
@@ -47,6 +48,9 @@ struct RNRiveError {
4748
case "TextRunNotFoundError":
4849
resultError = RNRiveError.TextRunNotFoundError
4950
break;
51+
case "DataBindingError":
52+
resultError = RNRiveError.DataBindingError
53+
break;
5054
default:
5155
return nil
5256
}

ios/RiveReactNativeView.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,26 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate
217217
let dataBindingViewModel = viewModel.riveModel?.riveFile.defaultViewModel(for: artboard) else { return }
218218

219219
func bindInstance(_ instance: RiveDataBindingViewModel.Instance?) {
220-
guard let instance = instance else { return }
220+
guard let instance = instance else {
221+
var error = RNRiveError.DataBindingError
222+
let configDescription: String = {
223+
switch dataBindingConfig {
224+
case .autoBind(let value):
225+
return "autoBind(\(value))"
226+
case .index(let value):
227+
return "index(\(value))"
228+
case .name(let value):
229+
return "name(\(value))"
230+
case .empty:
231+
return "empty"
232+
case .none:
233+
return "none"
234+
}
235+
}()
236+
error.message = "Failed to create data binding instance with config: \(configDescription)"
237+
onRNRiveError(error)
238+
return
239+
}
221240
viewModel.riveModel?.stateMachine?.bind(viewModelInstance: instance)
222241
self.dataBindingViewModelInstance = instance
223242

@@ -736,7 +755,12 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate
736755
}
737756
}()
738757

739-
guard let reg = registration else { return }
758+
guard let reg = registration else {
759+
var error = RNRiveError.DataBindingError;
760+
error.message = "\(propertyType) property not found at path: \(path)"
761+
onRNRiveError(error)
762+
return
763+
}
740764

741765
// Send initial value
742766
eventEmitter?.sendEvent(withName: key, body: reg.initialValue)

0 commit comments

Comments
 (0)