Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
표시
레이아웃
나란히 보기
합쳐 보기
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
비교 단위
스마트
구문
없음
모양 변경
처리
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
ReactSwitch.java
생성일
6년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
0 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
104 행
복사
16 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
120 행
복사
/*
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Facebook, Inc. and its affiliates.
*
*
* This source code is licensed under the MIT license found in the
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* LICENSE file in the root directory of this source tree.
*/
*/
package com.facebook.react.views.switchview;
package com.facebook.react.views.switchview;
import android.content.Context;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.SwitchCompat;
/**
/**
* Switch that has its value controlled by JS. Whenever the value of the switch changes, we do not
* Switch that has its value controlled by JS. Whenever the value of the switch changes, we do not
* allow any other changes to that switch until JS sets a value explicitly. This stops the Switch
* allow any other changes to that switch until JS sets a value explicitly. This stops the Switch
* from changing its value multiple times, when those changes have not been processed by JS first.
* from changing its value multiple times, when those changes have not been processed by JS first.
*/
*/
/*package*/ class ReactSwitch extends SwitchCompat {
/*package*/ class ReactSwitch extends SwitchCompat {
private boolean mAllowChange;
private boolean mAllowChange;
@Nullable private Integer mTrackColorForFalse;
@Nullable private Integer mTrackColorForFalse;
@Nullable private Integer mTrackColorForTrue;
@Nullable private Integer mTrackColorForTrue;
public ReactSwitch(Context context) {
public ReactSwitch(Context context) {
super(context);
super(context);
mAllowChange = true;
mAllowChange = true;
mTrackColorForFalse = null;
mTrackColorForFalse = null;
mTrackColorForTrue = null;
mTrackColorForTrue = null;
}
}
@Override
@Override
public void setChecked(boolean checked) {
public void setChecked(boolean checked) {
if (mAllowChange && isChecked() != checked) {
if (mAllowChange && isChecked() != checked) {
mAllowChange = false;
mAllowChange = false;
super.setChecked(checked);
super.setChecked(checked);
setTrackColor(checked);
setTrackColor(checked);
} else {
} else {
// Even if mAllowChange is set to false or the checked value hasn't changed, we still must
// Even if mAllowChange is set to false or the checked value hasn't changed, we still must
// call the super method, since it will make sure the thumb is moved back to the correct edge.
// call the super method, since it will make sure the thumb is moved back to the correct edge.
// Without calling the super method, the thumb might stuck in the middle of the switch.
// Without calling the super method, the thumb might stuck in the middle of the switch.
super.setChecked(isChecked());
super.setChecked(isChecked());
}
}
}
}
void setColor(Drawable drawable, @Nullable Integer color) {
void setColor(Drawable drawable, @Nullable Integer color) {
if (color == null) {
if (color == null) {
drawable.clearColorFilter();
drawable.clearColorFilter();
} else {
} else {
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
}
}
}
public void setTrackColor(@Nullable Integer color) {
public void setTrackColor(@Nullable Integer color) {
setColor(super.getTrackDrawable(), color);
setColor(super.getTrackDrawable(), color);
}
}
public void setThumbColor(@Nullable Integer color) {
public void setThumbColor(@Nullable Integer color) {
setColor(super.getThumbDrawable(), color);
setColor(super.getThumbDrawable(), color);
}
}
/*package*/ void setOn(boolean on) {
/*package*/ void setOn(boolean on) {
// If the switch has a different value than the value sent by JS, we must change it.
// If the switch has a different value than the value sent by JS, we must change it.
if (isChecked() != on) {
if (isChecked() != on) {
super.setChecked(on);
super.setChecked(on);
setTrackColor(on);
setTrackColor(on);
}
}
mAllowChange = true;
mAllowChange = true;
}
}
public void setTrackColorForTrue(@Nullable Integer color) {
public void setTrackColorForTrue(@Nullable Integer color) {
if (color == mTrackColorForTrue) {
if (color == mTrackColorForTrue) {
return;
return;
}
}
mTrackColorForTrue = color;
mTrackColorForTrue = color;
if (isChecked()) {
if (isChecked()) {
setTrackColor(mTrackColorForTrue);
setTrackColor(mTrackColorForTrue);
}
}
}
}
public void setTrackColorForFalse(@Nullable Integer color) {
public void setTrackColorForFalse(@Nullable Integer color) {
if (color == mTrackColorForFalse) {
if (color == mTrackColorForFalse) {
return;
return;
}
}
mTrackColorForFalse = color;
mTrackColorForFalse = color;
if (!isChecked()) {
if (!isChecked()) {
setTrackColor(mTrackColorForFalse);
setTrackColor(mTrackColorForFalse);
}
}
}
}
복사
복사됨
복사
복사됨
public void setWidth(@Nullable Float width) {
if (width == null) {
return;
}
// given width is in dp, but setSwitchMinWidth method needs input in pixels.
setSwitchMinWidth(dpToPixels(width));
}
private void setTrackColor(boolean checked) {
private void setTrackColor(boolean checked) {
if (mTrackColorForTrue != null || mTrackColorForFalse != null) {
if (mTrackColorForTrue != null || mTrackColorForFalse != null) {
// Update the track color to reflect the new value. We only want to do this if these
// Update the track color to reflect the new value. We only want to do this if these
// props were actually set from JS; otherwise we'll just reset the color to the default.
// props were actually set from JS; otherwise we'll just reset the color to the default.
Integer currentTrackColor = checked ? mTrackColorForTrue : mTrackColorForFalse;
Integer currentTrackColor = checked ? mTrackColorForTrue : mTrackColorForFalse;
setTrackColor(currentTrackColor);
setTrackColor(currentTrackColor);
}
}
}
}
복사
복사됨
복사
복사됨
private float dpToPixels(float dp) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
getContext().getResources().getDisplayMetrics()
);
}
}
}
저장된 비교 결과
원본
파일 열기
/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ package com.facebook.react.views.switchview; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; /** * Switch that has its value controlled by JS. Whenever the value of the switch changes, we do not * allow any other changes to that switch until JS sets a value explicitly. This stops the Switch * from changing its value multiple times, when those changes have not been processed by JS first. */ /*package*/ class ReactSwitch extends SwitchCompat { private boolean mAllowChange; @Nullable private Integer mTrackColorForFalse; @Nullable private Integer mTrackColorForTrue; public ReactSwitch(Context context) { super(context); mAllowChange = true; mTrackColorForFalse = null; mTrackColorForTrue = null; } @Override public void setChecked(boolean checked) { if (mAllowChange && isChecked() != checked) { mAllowChange = false; super.setChecked(checked); setTrackColor(checked); } else { // Even if mAllowChange is set to false or the checked value hasn't changed, we still must // call the super method, since it will make sure the thumb is moved back to the correct edge. // Without calling the super method, the thumb might stuck in the middle of the switch. super.setChecked(isChecked()); } } void setColor(Drawable drawable, @Nullable Integer color) { if (color == null) { drawable.clearColorFilter(); } else { drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY); } } public void setTrackColor(@Nullable Integer color) { setColor(super.getTrackDrawable(), color); } public void setThumbColor(@Nullable Integer color) { setColor(super.getThumbDrawable(), color); } /*package*/ void setOn(boolean on) { // If the switch has a different value than the value sent by JS, we must change it. if (isChecked() != on) { super.setChecked(on); setTrackColor(on); } mAllowChange = true; } public void setTrackColorForTrue(@Nullable Integer color) { if (color == mTrackColorForTrue) { return; } mTrackColorForTrue = color; if (isChecked()) { setTrackColor(mTrackColorForTrue); } } public void setTrackColorForFalse(@Nullable Integer color) { if (color == mTrackColorForFalse) { return; } mTrackColorForFalse = color; if (!isChecked()) { setTrackColor(mTrackColorForFalse); } } private void setTrackColor(boolean checked) { if (mTrackColorForTrue != null || mTrackColorForFalse != null) { // Update the track color to reflect the new value. We only want to do this if these // props were actually set from JS; otherwise we'll just reset the color to the default. Integer currentTrackColor = checked ? mTrackColorForTrue : mTrackColorForFalse; setTrackColor(currentTrackColor); } } }
수정본
파일 열기
/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ package com.facebook.react.views.switchview; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; /** * Switch that has its value controlled by JS. Whenever the value of the switch changes, we do not * allow any other changes to that switch until JS sets a value explicitly. This stops the Switch * from changing its value multiple times, when those changes have not been processed by JS first. */ /*package*/ class ReactSwitch extends SwitchCompat { private boolean mAllowChange; @Nullable private Integer mTrackColorForFalse; @Nullable private Integer mTrackColorForTrue; public ReactSwitch(Context context) { super(context); mAllowChange = true; mTrackColorForFalse = null; mTrackColorForTrue = null; } @Override public void setChecked(boolean checked) { if (mAllowChange && isChecked() != checked) { mAllowChange = false; super.setChecked(checked); setTrackColor(checked); } else { // Even if mAllowChange is set to false or the checked value hasn't changed, we still must // call the super method, since it will make sure the thumb is moved back to the correct edge. // Without calling the super method, the thumb might stuck in the middle of the switch. super.setChecked(isChecked()); } } void setColor(Drawable drawable, @Nullable Integer color) { if (color == null) { drawable.clearColorFilter(); } else { drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY); } } public void setTrackColor(@Nullable Integer color) { setColor(super.getTrackDrawable(), color); } public void setThumbColor(@Nullable Integer color) { setColor(super.getThumbDrawable(), color); } /*package*/ void setOn(boolean on) { // If the switch has a different value than the value sent by JS, we must change it. if (isChecked() != on) { super.setChecked(on); setTrackColor(on); } mAllowChange = true; } public void setTrackColorForTrue(@Nullable Integer color) { if (color == mTrackColorForTrue) { return; } mTrackColorForTrue = color; if (isChecked()) { setTrackColor(mTrackColorForTrue); } } public void setTrackColorForFalse(@Nullable Integer color) { if (color == mTrackColorForFalse) { return; } mTrackColorForFalse = color; if (!isChecked()) { setTrackColor(mTrackColorForFalse); } } public void setWidth(@Nullable Float width) { if (width == null) { return; } // given width is in dp, but setSwitchMinWidth method needs input in pixels. setSwitchMinWidth(dpToPixels(width)); } private void setTrackColor(boolean checked) { if (mTrackColorForTrue != null || mTrackColorForFalse != null) { // Update the track color to reflect the new value. We only want to do this if these // props were actually set from JS; otherwise we'll just reset the color to the default. Integer currentTrackColor = checked ? mTrackColorForTrue : mTrackColorForFalse; setTrackColor(currentTrackColor); } } private float dpToPixels(float dp) { return TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dp, getContext().getResources().getDisplayMetrics() ); } }
비교하기