Skip to content

Commit

Permalink
[Fabric] Create the corresponding ViewManager
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed Feb 28, 2022
1 parent 32885f5 commit c893370
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.rnnewarchitectureapp.components;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

public class AnswerViewer extends androidx.appcompat.widget.AppCompatTextView {

public AnswerViewer(Context context) {
super(context);
}

public AnswerViewer(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public AnswerViewer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.rnnewarchitectureapp.components;

import android.graphics.Color;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManagerDelegate;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.viewmanagers.AnswerViewerManagerDelegate;
import com.facebook.react.viewmanagers.AnswerViewerManagerInterface;

@ReactModule(name = AnswerViewerManager.REACT_CLASS)
public class AnswerViewerManager extends SimpleViewManager<AnswerViewer>
implements AnswerViewerManagerInterface<AnswerViewer> {

public static final String REACT_CLASS = "AnswerViewer";

private final ViewManagerDelegate<AnswerViewer> mDelegate;

public AnswerViewerManager() {
mDelegate = new AnswerViewerManagerDelegate<>(this);
}

@Nullable
@Override
protected ViewManagerDelegate<AnswerViewer> getDelegate() {
return mDelegate;
}

@NonNull
@Override
public String getName() {
return REACT_CLASS;
}

@NonNull
@Override
protected AnswerViewer createViewInstance(@NonNull ThemedReactContext reactContext) {
return new AnswerViewer(reactContext);
}

@Override
@ReactProp(name = "color")
public void setColor(AnswerViewer view, @Nullable String value) {
view.setTextColor(Color.parseColor(value));
}

@Override
@ReactProp(name = "step", defaultInt = 0)
public void setStep(AnswerViewer view, int value) {
view.setText("Step: " + value);
}

@Override
public void changeBackgroundColor(AnswerViewer view, String value) {
view.setBackgroundColor(Color.parseColor(value));
}

@Override
public void receiveCommand(@NonNull AnswerViewer root, String commandId, @Nullable ReadableArray args) {
mDelegate.receiveCommand(root, commandId, args);
}
}

0 comments on commit c893370

Please sign in to comment.