Skip to content

Commit 40ed0b8

Browse files
committed
Android: Intelligent null checking in fragment
1 parent b42db43 commit 40ed0b8

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Source/ZXing.Net.Mobile.Android/ZXingScannerFragment.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ private LinearLayout.LayoutParams getChildLayoutParams()
103103

104104
public void Torch(bool on)
105105
{
106-
scanner.Torch(on);
106+
scanner?.Torch(on);
107107
}
108108

109109
public void AutoFocus()
110110
{
111-
scanner.AutoFocus();
111+
scanner?.AutoFocus();
112112
}
113113

114114
public void AutoFocus(int x, int y)
115115
{
116-
scanner.AutoFocus(x, y);
116+
scanner?.AutoFocus(x, y);
117117
}
118118

119119
Action<Result> scanCallback;
@@ -134,45 +134,44 @@ public void StartScanning (Action<Result> scanResultHandler, MobileBarcodeScanni
134134

135135
void scan ()
136136
{
137-
if (scanner != null)
138-
scanner.StartScanning (scanCallback, ScanningOptions);
137+
scanner?.StartScanning (scanCallback, ScanningOptions);
139138
}
140139

141140
public void StopScanning ()
142141
{
143-
scanner.StopScanning ();
142+
scanner?.StopScanning ();
144143
}
145144

146145
public void PauseAnalysis ()
147146
{
148-
scanner.PauseAnalysis ();
147+
scanner?.PauseAnalysis ();
149148
}
150149

151150
public void ResumeAnalysis ()
152151
{
153-
scanner.ResumeAnalysis ();
152+
scanner?.ResumeAnalysis ();
154153
}
155154

156155
public void ToggleTorch ()
157156
{
158-
scanner.ToggleTorch ();
157+
scanner?.ToggleTorch ();
159158
}
160159

161160
public bool IsTorchOn {
162161
get {
163-
return scanner.IsTorchOn;
162+
return scanner?.IsTorchOn ?? false;
164163
}
165164
}
166165

167166
public bool IsAnalyzing {
168167
get {
169-
return scanner.IsAnalyzing;
168+
return scanner?.IsAnalyzing ?? false;
170169
}
171170
}
172171

173172
public bool HasTorch {
174173
get {
175-
return scanner.HasTorch;
174+
return scanner?.HasTorch ?? false;
176175
}
177176
}
178177
}

0 commit comments

Comments
 (0)