React Native UI Component

痴心易碎 提交于 2019-12-24 06:18:21

问题


When react native require this native ui component multiple time, starting from the second one, the previous became black.

Any ideas?

@Override
public String getName()
{
    return "JWPlayer";
}


@Override
public JWPlayerView createViewInstance(ThemedReactContext context)
{
    PlayerConfig playerConfig = new PlayerConfig.Builder().build();

    playerView = new JWPlayerView(context.getCurrentActivity(), playerConfig);
    playerView.setFullscreen(false, false);
    playerView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    playerView.addOnFullscreenListener(this);
    playerView.addOnPauseListener(this);
    playerView.addOnPlayListener(this);
    playerView.addOnSetupErrorListener(this);
    playerView.addOnErrorListener(this);



    return playerView;
}

回答1:


I also met this question. I solved the problem.

see same question ,

this

JWView.java :

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;


import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;

import com.longtailvideo.jwplayer.JWPlayerView;
import com.longtailvideo.jwplayer.configuration.PlayerConfig;

public class JWView extends FrameLayout {


    private final Context _context;
    private Activity activity = null;

    public JWView(Context context) {
        super(context);
        this._context = context;
        this.activity = ((ReactContext) getContext()).getCurrentActivity();

        PlayerConfig playerConfig = new PlayerConfig.Builder()
                .file("http://img.ksbbs.com/asset/Mon_1605/25d705200a4eab4.mp4")
                .autostart(false)
                .build();

        JWPlayerView playerView = new JWPlayerView(this.activity, playerConfig);


        addView(playerView);
    }

    private final Runnable measureAndLayout = new Runnable() {
        @Override
        public void run() {
            measure(
                    MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
            layout(getLeft(), getTop(), getRight(), getBottom());
        }
    };

    @Override
    public void requestLayout() {
        super.requestLayout();

        // The spinner relies on a measure + layout pass happening after it calls requestLayout().
        // Without this, the widget never actually changes the selection and doesn't call the
        // appropriate listeners. Since we override onLayout in our ViewGroups, a layout pass never
        // happens after a call to requestLayout, so we simulate one here.
        post(measureAndLayout);
    }

}

JWPlayerViewManager.java:

import java.util.List;
import java.util.ArrayList;

import android.app.Activity;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;


import com.longtailvideo.jwplayer.JWPlayerView;
import com.longtailvideo.jwplayer.configuration.PlayerConfig;


public class JWPlayerViewManager extends SimpleViewManager<JWView>
{


    @Override
    public String getName()
    {
        return "Jwplayer";
    }

    @Override
    public JWView createViewInstance(ThemedReactContext context)
    {
        return new JWView(context);
    }
}


来源:https://stackoverflow.com/questions/44935783/react-native-ui-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!