현업기록소 태그가 있는 포스팅들은 내가 실제로 업무를 하며 팀 내 위키에 공유용으로 적은 글을 보안상 문제요소들을 수정하여 옮긴 포스팅이며, 회고 및 복습을 위함이니 참고부탁합니다.
RN에서 아래와 같이 커스텀 뷰에 이벱트를 전달 받았을 때 호출할 함수를 등록합니다.
<MyCustomView
style={{flex:1}}
onPwdInputDone={this.doneInput}
/>
public class SampleViewManager extends SimpleViewManager<RelativeLayout> {
public static final String moduleName = "SampleView";
@Nullable
@Override
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
return MapBuilder.<String, Object>builder().put("onPwdInputDone", MapBuilder.of("registrationName", "onPwdInputDone")).build();
}
RCTEventEmitter를 통해서 이벤트를 전달합니다. 이때 인자는 WritableMap 으로 key, value 구성하여야 합니다.WritableMap keypadEvent = Arguments.createMap();
keypadEvent.putString("inputData", plainData);
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "onPwdInputDone", keypadEvent);
@interface RNTSecKeypadManager : RCTViewManager
@end
@implementation RNTSecKeypadManager
RCT_EXPORT_MODULE(RNTSecKeypad);
RCT_EXPORT_VIEW_PROPERTY(onPwdInputDone, RCTBubblingEventBlock)
...
@end
if (self.onPwdInputDone != NULL) {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:cipherString, @"inputData", nil];
self.onPwdInputDone(dict);
}